Consumes a nuget package containing msbuild targets with automatic package restore

I am creating a nuget package that will contain the MSBuild.targets and .props files as per nuget documentation (nuget 2.5+ required).

I intend to use it for automatic package recovery.

When I add the resulting package to csproj, two things happen:

As was expected:

<Import Project="..\packages\MyPackage.1.0.0\build\net40\MyPackage.props" Condition="Exists('..\packages\MyPackage.1.0.0\build\net40\MyPackage.props')" />
...
...
<Import Project="..\packages\MyPackage.1.0.0\build\net40\MyPackage.targets" Condition="Exists('..\packages\MyPackage.1.0.0\build\net40\MyPackage.targets')" />

      

Not expected:

<PropertyGroup>
<RestorePackages>true</RestorePackages>
...
</PropertyGroup>
...
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
    <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable 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('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  ...
</Target>

      

This "Not Expected" behavior is forest recovery with an integrated MSBuild package.

I removed these scaffolds manually as per the documentation , but when I push the project to the build server, the message automatec-package-restore appears, add scaffolding again, causing the build to fail.

This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is D:\TFSBuilds\...\.nuget\NuGet.targets.

      

Does anyone have a way to block / prevent these forests from being enabled when the package contains msbuild targets?

Update

Instead of a solution, I tried a workaround. That is, I created another nuget package to fix the missing nuget.targets file. When added to a project, this new package includes a target that DependsOnTargets EnsureNuGetPackageBuildImports and creates empty / valid nuget.targets. This satisfies the condition called from csproj scaffolding while still allowing the nuget package autorecovery feature to run on the build server.

<Target Name="NuGetPackAutomaticPackageRestorePreBuildWorkaround" BeforeTargets="EnsureNuGetPackageBuildImports"  Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')">
  <ItemGroup>
    <PatchTargets Include="$(MSBuildThisFileDirectory)TargetPatches\*.targets"/>
  </ItemGroup>
  <Copy
      SourceFiles="@(PatchTargets)"
      DestinationFolder="$(SolutionDir)\.nuget\"/>
</Target>

      

+3


source to share


1 answer


Is there a folder in the folder where the solution is located .nuget

? If so, try removing it.



I am setting up a solution that used the old package restore method (pre nuget 2.7) and had the same problem until I delete that folder.

0


source







All Articles