Build/Test Issues

Recommended project file modifications "corrupt" sln file.

Started by openshac on 4,921 views

I enabled NCrunch for a solution with about 20 projects. I got load failures for some of the projects so I followed the recommendations on the Project Build Platform And Configuration page and modified the PropertyGroup xml as recommended. The projects then built successfully.

However as soon as I saved my solution I noticed that my .sln file had changed/been corrupted.

This section of the .sln file
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Any CPU.ActiveCfg = Debug|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Any CPU.Build.0 = Debug|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Mixed Platforms.ActiveCfg = Debug|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Mixed Platforms.Build.0 = Debug|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Win32.ActiveCfg = Debug|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Win32.Build.0 = Debug|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|x86.ActiveCfg = Debug|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|x86.Build.0 = Debug|x86


was changed to:

{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Any CPU.ActiveCfg = Debug (Server)|x86

{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Mixed Platforms.ActiveCfg = Debug (Server)|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Mixed Platforms.Build.0 = Debug (Server)|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Win32.ActiveCfg = Debug (Server)|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|Win32.Build.0 = Debug (Server)|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|x86.ActiveCfg = Debug (Server)|x86
{4767FA9B-1487-4023-A380-B070F8C6A465}.ASPNET Debug|x86.Build.0 = Debug (Server)|x86


Where Debug Server is a custom configuration that I am using.

When I click on the project properties Debug is now missing from the Configuration dropdown too. It's also missing in the solution configuration tool.

One thing I've noticed is that the first PropertyGroup in my project file has:

 <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>


Changing AnyCPU to x86 seems to make the problem go away, but I don't understand why or if this is a valid change.
In my original Mickey Mouse solution that I used for initial testing of NCrunch having AnyCPU specified didn't cause any problems.

Could you explain what I am doing wrong?

Thanks
Hi, thanks for posting!

The solution file needs to work in alignment with the configuration groups specific inside the project files. VS must have automatically aligned the project file as soon as it worked out that you'd fixed up your project files. Note that you can easily create a new solution configuration inside the VS configuration manager to represent any updated configuration groups inside your project files.

I can't for certain say why changing the platform from AnyCPU to x86 would allow NCrunch to build your projects. This would depend upon the structure of your solution and the nature of the error. My first guess would be that you have a project (or a DLL) which is set to build only to x86, and therefore requires those projects depending on it to be built for the same platform. AnyCPU and x86 do create small differences in the DLL file that is output from the compiler, and they are not necessarily compatible at run time. It may be worth working your way up the dependency chain inside your solution to figure out which project requires x86, then examine its references to see if there is a reason for it.
The code in the project file means "if no value for the variable Platform is set, then set it to AnyCPU". However, from your description, your project does not have such a platform. So when - for whatever reason - NCrunch builds the project without any platform set, the platform is set to AnyCPU. But since the rest of your project file uses x86, all the settings particular to that platform are not set, resulting in your problems.

This error does not occur in your initial testing solution because you likely had a platform AnyCPU there.

Note that the project files generated by Visual Studio use AnyCPU as default value if nothing is set. This is unfortunately never adjust by VS, even if you delete that platform. The same is true for the configuration, which defaults to Debug. So you'll need to manually edit the project file.
Thanks for your email Daniel,

So are you saying that it's OK for me to change AnyCPU to x86 at the top of each project file?
Exactly. This should match one of the actual platforms in your project file.

Note that this is only used when no platform value is set. When building from Visual Studio, it always sets the value, so you could write whatever you wanted and wouldn't notice any difference.

Post a reply

Log in to reply.