Jeremy F
Jeremy F

Reputation: 467

All "EnsureNuGetPackageBuildImports" target steps added by various nuget package reference in Visual Studio 2017 .sln cause build error in TeamCity

Solution build failing in TeamCity for a project that references nuget packages that add condition entries to the .csproj file for various .targets and .props files. Works in Visual Studio without issue.

Does anyone have any idea what the issue is or what the fix/workaround is? I can comment out the section entirely and the build works without issue. Are these types of checks supported by TeamCity?

Many people seem to run into issues with these targets and frustration is shared here but this is not in the context of TeamCity -> https://github.com/NuGet/Home/issues/3320

TeamCity Build Steps

  1. Runner Type: NuGet Installer (this references the .sln)
  2. Runner Type: Visual Studio (sln)

TeamCity build error:

Note that I can move around the entries and whichever one is first will cause the build to fail.

C:\TeamCity\buildAgent\work\4z4520g0d4f45ge5\test\MyCompany.SomeProject\src\MyCompany.SomeProject.Test\MyCompany.SmokeTests.Test.csproj(114, 5):
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\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props.

Project (.csproj) Content That Triggers Errors

  <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\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
    <Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
    <Error Condition="!Exists('..\..\packages\NUnit.3.13.3\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\NUnit.3.13.3\build\NUnit.props'))" />
    <Error Condition="!Exists('..\..\packages\NUnit3TestAdapter.4.5.0\build\net462\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\NUnit3TestAdapter.4.5.0\build\net462\NUnit3TestAdapter.props'))" />
    <Error Condition="!Exists('..\..\packages\Selenium.WebDriver.4.13.1\build\Selenium.WebDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Selenium.WebDriver.4.13.1\build\Selenium.WebDriver.targets'))" />
    <Error Condition="!Exists('..\..\packages\OctoPack.3.6.5\build\OctoPack.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\OctoPack.3.6.5\build\OctoPack.targets'))" />
</Target>

Background:

I have been successfully using TeamCity for 7 years to build a rather large Visual Studio 2017 .sln file without issue. I'm adding a new .sln file to this repository to hold an ancillary project for selenium tests. This new solution contains a single project that contains references to several nuget packages that all add tags to the .csproj project file. These tags are in a "EnsureNuGetPackageBuildImports" node. Any entry in this node fails with the a build error like I've mentioned above.

Upvotes: 1

Views: 427

Answers (1)

Jeremy F
Jeremy F

Reputation: 467

Was able to find the issue myself and will leave here in case someone else encounters a similar issue in the future. The error I was seeing when built inside CI/CD was accurate, some of the files referenced from the .csproj file were indeed missing when the packages were referenced from source control. The issue was our .gitignore had a specific unignore for a 'build' folder that can exist in some nuget packages. I had placed a new packages folder in a subdirectory of our source control folder hierarchy that the unignore did not apply to and as a result I was accidentally excluding some nuget package resources from a 'build' folder. Added a new entry to unignore this folder at the new directory hierarchy and once commited to source control no issues when building inside TeamCity on the build server.

Upvotes: 1

Related Questions