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

Notification

Icon
Error

Issue when using conditional compilation symbols in linked file
yanglee
#1 Posted : Friday, May 31, 2013 4:48:23 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/25/2012(UTC)
Posts: 89
Location: China

Thanks: 23 times
Was thanked: 19 time(s) in 18 post(s)
Hi,

Here is an example project that can reproduce the issue:
https://dl.dropboxusercontent.com/u/46508238/forum.ncrunch.net/TestNCrunch-2013-06-01.zip

Steps to reproduce the issue:
1. Create a new solution with a Class Library project and a Unit Test project.
2. Menu > Build > Configuration Manager > Add 'x86' as the platform for the test project.
3. Add 'TEST' to the 'Conditional compilation symbols' of the test project.
4. Add the following classes in Class Library project:

Code:
    public class Class1
    {
        public Class1()
        {
#if(!TEST)
            new Class2();
#endif
        }
    }

    public class Class2
    {
    }


5. Link Class1 to the test project.
6. Enable NCrunch.
7. NCrunch outputs the following build error:

Code:
..\TestNCrunch\Class1.cs (11)#0: 
The type or namespace name 'Class2' could not be found 
(are you missing a using directive or an assembly reference?)



To workaround this issue:
1. Menu > Build > Configuration Manager > Switch to 'Any CPU' for the test project.
2. Add 'TEST' to the 'Conditional compilation symbols' of the test project.
3. Menu > Build > Configuration Manager > Switch back to 'x86' for the test project.


Cheers,

Yang
Remco
#2 Posted : Saturday, June 1, 2013 12:27:23 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Yang,

Thanks for sharing this! I was able to solve this problem by adjusting the NCrunch configuration for the test project, setting 'Use build platform' to x86. The core issue is that NCrunch doesn't make use of the settings in the Visual Studio Configuration Manager when building projects. It instead relies on the MSBuild defaults, which is something that takes many people by surprise. Although it could be considered a feature gap, the reasoning behind this approach was to reduce the number of edge cases around Visual Studio integration - particularly as when the Visual Studio Configuration Manager configuration is changed, the entire NCrunch engine would then need to be reset and all projects reloaded.

It's generally considered good practice to try and make sure that projects can always be built under their default MSBuild build configuration. This extends beyond just NCrunch as it can also make the projects more likely to work with other build tool and build servers.


Cheers,

Remco
1 user thanked Remco for this useful post.
yanglee on 6/1/2013(UTC)
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.027 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download