Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Building C# solution with some C++/CLI references
LeeMent
#1 Posted : Tuesday, June 6, 2017 9:43:45 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/5/2017(UTC)
Posts: 2
Location: United Kingdom

Hi,

I apologise for raising this issue, as I know you don't strictly support this setup, but I'm at a loss on how to move forward, and was wondering if anyone had any quick pointers if they have been in a similar situation.

I'm using Visual Studio 2015 and .NET framework 4.6.2.

I have a C# project that builds an assembly. This project is referenced by my C++ project (compiled managed). When I build in Visual Studio or MSBuild, all is well. When NCrunch is enabled and does its build, it can't find the C# assembly to build the C++ project.

I looked in the NCrunch generated C++ project file and it is correctly translating the C# project reference into an assembly reference within the NCrunch workspace; so it "knows" where the dll is located for the C# project.

Unfortunately, to access the managed code in C++ you need a:

Code:
#using <myCSharpAssembly.dll>


which requires the use of the /AI compiler flag

This compiler flag translates to a
Code:
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <AdditionalUsingDirectories>..\bin\$(Configuration)</AdditionalUsingDirectories>


within the project file, pointing to the output directory of where my C# assembly is built.

I think it is this compile option that is causing my issues in finding the assembly at compile time, as it can't be translated onto the NCrunch workspace.

Does anyone have any workarounds for this issue?

Cheers.
Remco
#2 Posted : Tuesday, June 6, 2017 9:11:35 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for sharing this issue.

It's unfortunately because of issues like this one that the decision was eventually made not to have official support for C++ builds under NCrunch. While many use cases still work, there were just too many edge cases (like this one) that seemed to need their own special handling in the engine. In most cases where I've seen people successfully use C++ projects under NCrunch, it's been the C# projects referencing the C++ ones, instead of the other way around.

The only 'easy' way I can suggest to make this work would be to scrap the project reference between the C++ project and the C# project, and use an assembly reference instead that points to the .dll output from your C# project. This means you'll need to perform a foreground build of your solution every time you want NCrunch to run on updated code, and you'll also lose code coverage, which is far from ideal.

The other option is to make changes to the MSBuild .targets involved here. I can't provide specific guidance on this, but all languages under .NET have their own set of specific .targets files usually stored under the MSBuild or .NET installation directory. These targets contain a range of steps that translate the project XML into parameters that are eventually passed into the compiler. Almost all components of the build system can be overridden by replacing factory build targets with your own targets declared within the project file (NCrunch does this quite heavily for its own builds). If you can find the build logic dependent on the AdditionalUsingDirectories declaration, maybe you can make it smarter to include paths from the Reference declarations also.
LeeMent
#3 Posted : Wednesday, June 7, 2017 11:50:08 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/5/2017(UTC)
Posts: 2
Location: United Kingdom

Thanks for the response.

I understand the complexity of adding C++ to NCrunch is a bit of a rabbit warren. Thanks for taking the time to provide an answer. I just wish the architecture I had to deal with was a little less rigid.

I think at the moment - unless I think of something else - I'll have to just have some partial coverage of my solution and lose the rest. If I find anything else out, I'll post here.

Thanks
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.033 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download