Fixing Msbuild Error msb3247 - Found conflicts between different versions of the same dependent assembly.

Set MsBuild Verbosity to find out which assemblies conflict: http://msdn.microsoft.com/en-us/library/ms164311.aspx msbuild.exe .\Compile.msbuild /verbosity:detailed ... There was a conflict between "xxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx" and "xxx, Version=1.0.12152.1, Culture=neutral, PublicKeyToken=xxx". "xxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx" was chosen because it was primary and "xxx, Version=1.0.12152.1, Culture=neutral, PublicKeyToken=0313e76cb5077f22" was not. References which depend on "xxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx" [D:\Projects\abc\bin\xxx.dll]. D:\Projects\abc\bin\xxx.dll Project file item includes which caused reference "D:\Projects\abc\src\Web.BuildServer\bin\xxx.dll". xxx References which depend on "xxx, Version=1.0.12152.1, Culture=neutral, PublicKeyToken=xxx" []. D:\Projects\abc\src\packages\yyy\lib\Net40\yyy.dll Project file item includes which caused reference "D:\Projects\abc\src\packages\yyy\lib\Net40\yyy.dll". yyy ... What means yyy references a version of yyy other than the one references by the project or another assembly. Check the Config files For Web-Applications the Web.config for all other project types the App.config file (even for class libraries). Make sure you don’t have a <runtime> section pointing to the wrong assembly version. Fix the error by binding the correct version. <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31BF3856AD364E35" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="1.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> Helpful utilities https://github.com/mikehadlow/AsmSpy

MsBuild finding directories if not given as parameter

I’m a lazy developer. Being lazy does not mean I avoid to work. It means that I like to reflect things I am doing and optimize and atomize stuff to get more time on the valuable tasks. Code generation is a tool I tend to use quite regularly and T4 is at most my generator of choice. Generated files can cause a lot of merging conflicts. So they are not to be checked into my source control system (currently my choice is HG/Mercurial). For the build server this means the files do not exist when the repository is freshly checked out – they need to be generated during the build right before the compile happens. With code generation I usually tend to use a pattern that is for example also used by ASP.NET MVC Views/Controller generation: If there is a local directory containing code generation templates, use it. Otherwise utilize the system wide templates. MsBuild version 4.0 comes with a feature called property functions. This allows to place for instance a “find directories” inside a property group. I use them to: Allow to set a system wide template directory using the command line/the MsBuild API. If no directory is set use a local directory. If non of the above is applied set a fallback default. Here is the XML snippet that shows how to use the pattern: <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Generate" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <RootFolder>..\src</RootFolder> <CodeGeneratorDir Condition=" '$(CodeGeneratorDir)' == '' " /> <LocalCodeGeneratorDir> CodeGenerationTemplates </LocalCodeGeneratorDir> <CodeGeneratorDirFallback> C:\CodeGenerationTemplates </CodeGeneratorDirFallback> </PropertyGroup> <ItemGroup> <ModelFiles Include="..\src\**\*.xdml" /> <TemplateDirectory Include="$(CodeGeneratorDir);" /> <TemplateDirectory Condition=" '$(CodeGeneratorDir)' == '' " Include="$([System.IO.Directory]::GetDirectories( &quot;$(RootFolder)&quot;, &quot;$(LocalCodeGeneratorDir)&quot;, System.IO.SearchOption.AllDirectories))" /> <TemplateDirectory Condition=" '@(TemplateDirectory)' == '' " Include="$(CodeGeneratorDirFallback)" /> </ItemGroup> <Target Name="Generate"> <Message Text="@(TemplateDirectory)" /> <Message Text="@(ModelFiles)" /> </Target> </Project>