We have a .Net 3.5 application that is created using some scripts that call msbuild.exe
Recently, all of our machines began to automatically upgrade from .Net 4.0 to .Net 4.5 as part of the company's entire policy, and our build scripts started to fail.
The errors mentioned are that they cannot find a link to the assembly, for example:
error CS0012: The type 'System.Drawing.Image' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System.Drawing, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'.
It seems that in each case we are trying to build project A, which has a link to project B, and project B has a link to library X and gets an error for which project A needs a link to library X.
The workaround is to uninstall 4.5, uninstall 4.0, and then reinstall 4.0, however this is time consuming and impractical in an environment where updates are often silent and automatic.
I already tried using the following msbuild switches, no luck
/toolsversion:3.5 - Exception near Func undefined/toolsversion:4.0 - Doesn't work because 4.5 replaced 4.0 tools/p:TargetFrameworkVersion="v3.5" - Same errors/p:VisualStudioVersion=11.0 - same error * `in csproj file - same error already exists
The .csproj files already have <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> specified in each csproj file in my solution, and ToolsVersion="4.0" .
I also tried changing TargetFrameworkVersion to 4.0, and this does not work either.
I found several notes on the Internet that Microsoft changes the OnlyReferenceAndBuildProjectsEnabledInSolutionConfiguration flag from false to true during the update 4.0 to 4.5, however manually this flag in csproj files also does not fix the problem.
<OnlyReferenceAndBuildProjectsEnabledInSolutionConfiguration> false </OnlyReferenceAndBuildProjectsEnabledInSolutionConfiguration>
Why msbuild cannot find these child assemblies after upgrading from 4.0 to 4.5 and how can I fix it?
Update
I finally figured out the source of the problem, but I have no idea how this can happen.
ProjectA has a class that inherits from an abstract class in ProjectB, and one of the properties of ProejctB.BaseClass is of type System.Drawing.Image .
namespace ProjectA { public class SomeClass : BaseClass { } } namespace ProjectB { public abstract class BaseClass { public System.Drawing.Image GetImage() { }; } }
From everything that I read on the Internet, and from creating my own test project, this means that ProjectA needs a reference to System.Drawing.Image for the assembly.
But for some reason this limitation does not seem to matter for our project when starting with msbuild 4.0 or VS VS. He gladly creates ProjectA without reference to System.Drawing.Image .
Even after upgrading to .Net 4.5, I can still successfully build ProjectA from Visual Studio 2010 without adding a link to System.Drawing.Image , however the creation using msbuild now (correctly?) Fails. I also get support errors when building in VS 2012 Express, so everything that allows me to do this seems to have been fixed in newer versions of VS.
Currently, I went through all 148 projects in our solution and fixed all the links, however I want to leave this question open in order to try to get an answer on why I can build ProjectA using msbuild 4.0 or Visual Studio 2010 without a link to System.Drawing.Image .
I have already determined that I cannot easily reproduce the behavior in the test project, so I best assume that this is either some kind of configuration, part of the build scripts, or an error that existed back when .sln or .csproj files were created and no longer exist in newly created projects.