views:

227

answers:

3

Immediately after we upgraded to visual studio 2010 and the 4.0 framework our trunk build started breaking with the Could not load file or assembly error.

We determined that a 3.5 project couldn't reference a 4.0 project else we'd get this error because, as the error states, This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Fair enough.

We've since resolved this and the trunk has been building fine.

I recently did a branch and tag, however, and suddenly this error has resurfaced when I try to build the branch; except the error is regarding one of our own .net 4.0 project's reference to System.Configuration DLL.

Towps.Namespace.MyService.csproj in Core.Dev\Towps\Projetcs\Application\MyService:
RG0000: Could not load referenced assembly

"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll".
Caught a BadImageFormatException saying "Could not load file or assembly
'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' or one of its dependencies.
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.". in ResGen(0, 0)

I tried setting the specific version property on that system.Configuration DLL ref to true.
I can see in it's properties that the runtime version is v4.0.30319 and the Version is 4.0.0.0.
The path to the DLL ref is C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Configuration.dll which to me looks fine.

The target framework for the csproj file that CrusieControl is using MSBuild to try to build is targeting framework 4.0. Again seems fine.

It builds in the IDE for both trunk & branch. Cruise Control build it in the trunk. The branch build fails when CrusieControl tries to build.

Any ideas what could be happening?

It could be an MSBuild mismatch but I've scanned the config files and msbuild proj files that CrusieControl is using and there are no references to older MSBuilds; which makes sense since all those were updated to get the trunk working.

The branch was simply a copy of the trunk so I'm having difficulty determining what could be the difference!

Any help would be great. Thanks.

+1  A: 

I'm having a similar-but-differrent problem. When I set the /tv switch on the msbuild command line to target the 3.5 framework, my build fails as the project is still trying to reference the 4.0 version of the system.* libraries. All of the projects have the ToolsVersion attribute set to 4.0.

In researching, I came across this: http://msdn.microsoft.com/en-us/library/bb383985.aspx. At the bottom, there's mention of an order of precendence for setting the target version. I'm just wondering if there's not something else in your build command chain that's overriding the target version and forcing your build to 3.5?

I realise this is probably not much help, but I was just passing through. :)

Geoff Bennett
`/tv` is tools version not target version. tv sets what compiler(csc.exe for example) is used not what framework it tries to load dll's from.
Maslow
Thanks. Yes, I actually found that out in the end too. You need to set the TargetFrameworkVersion property. I just added this: /p:TargetFrameworkVersion=v3.5 to the command line.
Geoff Bennett
A: 

The difference could easily be hint paths no longer lining up on the new branch. However there's not a log to go on in your description. What are the command line options you are passing? In ccnet.config and also any others that may get in if ccnet.config is pointing at a build script that calls msbuild instead of directly to a .sln or .csproj file.

Turn on /v:d for the msbuild on BOTH and then compare the reference resolutions (or build order, etc..) for that assembly or other ones involved/near it.

Also are you providing the path to msbuild on both?

msbuild4="C:\WINNT\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"

<msbuild>
    <executable>$(msbuild4)</executable>

in your ccnet.config?

I've seen it report the 2.0 build executable during a msbuild4 /tv:3.5:

<Message Text="MSBuildToolsPath:$(MSBuildToolsPath)" />
<Message Text="MSBuildToolsVersion:$(MSBuildToolsVersion)" />

MSBuildToolsPath:C:\WINNT\Microsoft.NET\Framework\v2.0.50727
MSBuildToolsVersion:2.0

so that didn't seem very useful.

I'd like to see the config blocks for both branch and trunk.

I know I had some paths in the buildscript that failed in my branch because there was a hardcoded path that would not be valid for the branch. I had to adjust the ccnet.config to pass in arguments for those items to override for the branch.

Maslow
A: 

It turns out that after I branched, all the .proj files in my branch build directory that cc.net uses were back to using ToolVerison="3.5". I thought I committed all the ToolsVersion="4.0" proj and config changes to the trunk from which I made the branch; evidentially not.

towps