2
votes

I created empty WebAPI project and checked in the project into TFS. I got following error on build:

Error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.

I then removed following block from .csproj file as advised in previous topics about same error:

  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
    <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
  </Target>

After I remove this xml part from .csproj TFS build successfully builds. I want to understand why is Visual Studio 2015 adding following Target part inside of .csproj which makes TFS build fail.

1

1 Answers

1
votes

The Microsoft.Net.Compilers package and NuGet added those Props imports.

The package (as of 1.1.1) contains a set of MSBuild Properties that the developers suggest your project has to ensure it can be compiled the way they indetended.

To ensure that those properties are imported into MSBuild when your project is built, the csproj file is edited during package installation to include a check that they exist, or raise an error.

Usually you see the error when you don't have the NuGet package restored during build, if you look at the path in the "Error" condition, is the Microsoft.Net.Compilers.1.0.0 folder there?

Sometimes this can happen when you upgrade a package (say to 1.1.1) and the Import is left to the wrong path.