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

Notification

Icon
Error

Won't build a project that uses /unsafe compiler switch
TuxedoOnATShirt
#1 Posted : Wednesday, June 13, 2012 3:45:13 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/13/2012(UTC)
Posts: 1
Location: San Diego

So I'm trying to get up to speed on NCrunch on a solution at work and am at the phase of addressing various issues that'll prevent NCrunch from building the solution successfully.

The current issue is that NCrunch won't build a project that uses an unsafe block of code.
The project file in my solution is using the /unsafe build flag(rather it's checked anyay on my project page in the IDE & it builds normally), yet it's not building w/ NCrunch.

Doesn't NCrunch use my project file pretty much as is to build the project in it's temp/working directory?

How can I specify additional build switches to a project in cases like this to ensure it'll build?


Remco
#2 Posted : Wednesday, June 13, 2012 4:18:10 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,

NCrunch does use the standard build process with the command line flags in the same manner as any command line MSBuild action, and I'm fairly certain I've seen it work with /unsafe before without problems. Most likely what you're experiencing is the result of a more subtle issue. Can you share the build error you're experiencing?

Often a good way to analyse build issues such as this is to inspect the workspace used for the project by NCrunch and to try and find a way to build the project in this workspace by using msbuild.exe on the command line. The easiest way to find the workspace is to right-click the failed project in the Tests Window, then choose Advanced->Browse to workspace.
philAtkin
#3 Posted : Thursday, October 4, 2012 10:40:29 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/25/2012(UTC)
Posts: 5
Location: Cambridge, UK

Thanks: 1 times
I was having the same problem. It turned out that, while I was successfully building one combination of configuration and platform in the IDE, NCrunch was trying to build a different combination - one for which I had not set the 'Allow unsafe code' checkbox (in fact, I hadn't even realized that this flag was specific to a configuration/platform combination.

I must say, I've had several baffling problems associated with the fact that NCrunch isn't building the configuration/platform that I'm expecting it to.

Phil Atkin
Remco
#4 Posted : Thursday, October 4, 2012 8:06:30 PM(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 Phil -

NCrunch will always use the default build $(Configuration) and $(Platform) that is specified in your .proj files. This can sometimes be a cause of confusion for people, as the build configuration in the Visual Studio IDE allows you to choose (and thus inject) different values into the build for these two properties. Basically this means that if the build settings in your project files are out of alignment if your IDE, then you may experience different build behaviour to what you are expecting.

The logical solution to this would seem to be for NCrunch to try and follow the selected build configuration within Visual Studio, although there are huge problems with this approach. The chosen build configuration can have implications for the logic and structure of the source code under test, and as such every change to the VS build configuration would need to be associated with completely throwing away all code coverage information and test results. For solutions with tests that can run through under 30 seconds this isn't a big deal, but NCrunch is often also used with solutions with test running times into the hours, for which throwing away this information would be particularly painful.

NCrunch does contain a project-level configuration setting, 'Use build configuration', allowing you to specify which value should be injected as the $(Configuration) MSBuild property. My usual advice is to try and align your .proj build defaults with the configuration and platform you would normally use while developing in Visual Studio, as this is generally better practice and can also help you when working with other tools (such as build servers).


Cheers,

Remco
philAtkin
#5 Posted : Friday, October 5, 2012 8:41:18 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/25/2012(UTC)
Posts: 5
Location: Cambridge, UK

Thanks: 1 times
Hi Remco,

Thanks for the reply. Here's my two pen'o'rth:
* As far as I know, there's no way to see, nor set, the default configuration and platform using the VS IDE. That makes it particularly difficult to know how NCrunch will build the project.
* Whilst I'd found the 'Use build configuration' setting, most of the problems I had were to do with the _platform_ setting, which can't be overridden in the same way.

Once set up I find NCrunch a real pleasure, and I recognise that the problems I've had probably aren't typical.

Cheers,

Phil
Remco
#6 Posted : Friday, October 5, 2012 10:58:02 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 Phil -

I'll add the platform property to a new configuration option in the upcoming 1.42 release. It really should have been in there much earlier and I'm not sure if I can give any good reason for having left it this late.

As far as I know, the default configuration/platform in the .proj files can only really be reliably edited by changing the project XML manually. Most of the people that have problems with inconsistent $(Configuration) properties usually have projects that they've upgraded from different versions of Visual Studio. VS tends to manipulate the build configurations indirectly through the 'Configuration Manager', although I can't really say exactly what kind of rules the configuration manager follows as it is version specific and perhaps a little over simplified.

Thanks for your feedback!


Cheers,

Remco
philAtkin
#7 Posted : Friday, October 5, 2012 11:50:30 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/25/2012(UTC)
Posts: 5
Location: Cambridge, UK

Thanks: 1 times
Hi Remco,

Thanks for the reply. I've just noticed the Test Settings\Use CPU architecture setting. How does this relate to the Platform setting for the build? Does this mean that in fact you've already implemented the required feature?

Phil
Remco
#8 Posted : Friday, October 5, 2012 10:30:23 PM(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)
The 'Use CPU Architecture' setting is specific to the test environment, and doesn't have an impact on the build. This setting actually exists primarily for frameworks like MSTest, where there is no clear standard between test runners which CPU architecture should be used for execution when the test project is set to build with AnyCPU. The platform configuration option will need to be a separate one for the build (although I guess there is a relation between them!).


Cheers,

Remco
1 user thanked Remco for this useful post.
philAtkin on 10/7/2012(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.068 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download