Build/Test Issues

Issue when using conditional compilation symbols in linked file

Started by yanglee on 7,423 views

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:

    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:

..\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
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

Post a reply

Log in to reply.