MSBuild fails for solution with project dependencies

1.3k views Asked by At

The build for my solution, which contains multiple projects, suddenly appears to be broken and the cause of the issue isn't clear. All of the projects in the solution target the same framework (4.5.1), however, some of the projects' dependencies might be targeting an earlier version of the framework. As of last week, we were able to successfully build solutions that fall under this scenario. Starting last Thursday, the builds appear to be broken without any changes to the build server or the solution.

To illustrate and remove some of the complexities with our production setup, I created a sample solution which mimics the behavior.

Project structure:

  • CBI Solution
    • CBI website
    • CBI Implementation Library
    • CBI Core library, defining the interfaces

Target Framework Version for the website and class libraries is 4.5.1

Replication Steps

Solution 1

Github repo: https://github.com/NikitaGolovko/Solution1.git

Build, using MSBuild 14. My command is:

msbuild.exe "%SOLUTION1PATH%\CBILite.sln" /p:platform="Any CPU" /p:configuration="Release" /v:d

Output

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /localhost_61806 -p cbi\ -u -f PrecompiledWeb\lo
  calhost_61806\
  Microsoft (R) ASP.NET Compilation Tool version 4.7.2046.0
  Utility to precompile an ASP.NET application
  Copyright (C) Microsoft Corporation. All rights reserved.


Done executing task "AspNetCompiler".
Task "Message" skipped, due to false condition; (!((false) or ('$(AspNetConfiguration)' == 'Debug') or ('$(AspNetConfig
uration)' == 'Release'))) was evaluated as (!((false) or ('Release' == 'Debug') or ('Release' == 'Release'))).
Done building target "Build" in project "cbi.metaproj".
Done Building Project "D:\Work\DotNet\Nikita\Solution1\cbi.metaproj" (default targets).

Done executing task "MSBuild".
Done building target "Build" in project "CBILite.sln".
Done Building Project "D:\Work\DotNet\Nikita\Solution1\CBILite.sln" (default targets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.10

Full output is located here: https://github.com/NikitaGolovko/Solution1/blob/master/MSBuild_Output.txt

Solution 2

Github Repo: https://github.com/NikitaGolovko/Solution2.git

The solution is nearly identical to the Solution1, with the only exception being a dependency for Unity in CBI Implementation library. To simplify the process and eliminate the nuget restore step, I have included nuget packages with the solution.

Build, using MSBuild 14. My command is:

msbuild.exe "%SOLUTION2PATH%\CBILite.sln" /p:platform="Any CPU" /p:configuration="Release" /v:d

Output

  C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /localhost_61806 -p cbi\ -u -f PrecompiledWeb\lo
  calhost_61806\
  Microsoft (R) ASP.NET Compilation Tool version 4.7.2046.0
  Utility to precompile an ASP.NET application
  Copyright (C) Microsoft Corporation. All rights reserved.

D:\Work\DotNet\Nikita\Solution2\cbi\Index.aspx.vb(5): error BC30002: Type 'CBILite.Calculator' is not defined. [D:\Work
\DotNet\Nikita\Solution2\cbi.metaproj]
  The command exited with code 1.

Done executing task "AspNetCompiler" -- FAILED.
Done building target "Build" in project "cbi.metaproj" -- FAILED.
Done Building Project "D:\Work\DotNet\Nikita\Solution2\cbi.metaproj" (default targets) -- FAILED.

Done executing task "MSBuild" -- FAILED.
Done building target "Build" in project "CBILite.sln" -- FAILED.
Done Building Project "D:\Work\DotNet\Nikita\Solution2\CBILite.sln" (default targets) -- FAILED.


Build FAILED.

Full output is located here: https://github.com/NikitaGolovko/Solution2/blob/master/MSBuild_Output.txt

Observations

Bin folder

When looking in the bin folder of the website, I notice that CBILite.dll is missing after the build for Solution2, but present in Solution1.

TargetFrameworkVersion

Passing TargetFrameworkVersion in the MSBuild arguments does not appear to influence the build. I have attempted to pass 4.5, 4.5.1 to no avail. HOWEVER passing 3.5 results in the successful build. This is extremely strange.

Metaproj

When comparing Metaproj files generated for both solutions, the only observable and seemingly important difference is the lack of the TargetFrameworkVersion element. Solution1 (without dependencies), contains v.4.0 element. Solution2 (with the dependency) does not. I didn't include metaproj files in the repo but can share them if needed.

Visual Studio

Building the solution in Visual Studio works just fine.

Additional thoughts

The issue manifested itself rather suddenly and seems to be affecting most of our solutions that have mixed projects (C#/VB + website). Web Projects continue to function normally.

I've attempted to use MSBuild 15, but it resulted in the same behavior.

There are a few workarounds

  1. Retaining the metaproj file with the solution and modifying it manually by adding v4.5.1 element.
  2. Adding an additional build step to manually copy CBILib.dll into the website project (via the batch file or other means).
  3. Adding a refresh file for the website pointing to CBILib/bin/Release folder

While all of these solutions might work, they're certainly hacks and will present problems in the future.

I'm hoping someone else has a better suggestion on how to handle this.

1

There are 1 answers

0
polina-c On

Make sure you have installed the following NuGet packages:

  • Microsoft.NET.Test.Sdk

  • MSTest.TestAdapter

  • MSTest.TestFramework

  • Microsoft.NETCore.App (if you use .NET Core)