使用包含msbuild目标的nuget包进行自动包还原



我正在编写一个nuget包,该包将根据nuget文档包含MSBuild.targets和.props文件(需要nuget 2.5+)。

我打算将它与自动程序包恢复一起使用。

当我将生成的包添加到csproj中时,会发生两件事:

如预期:

<Import Project="..packagesMyPackage.1.0.0buildnet40MyPackage.props" Condition="Exists('..packagesMyPackage.1.0.0buildnet40MyPackage.props')" />
...
...
<Import Project="..packagesMyPackage.1.0.0buildnet40MyPackage.targets" Condition="Exists('..packagesMyPackage.1.0.0buildnet40MyPackage.targets')" />

不期望:

<PropertyGroup>
<RestorePackages>true</RestorePackages>
...
</PropertyGroup>
...
<Import Project="$(SolutionDir).nugetNuGet.targets" Condition="Exists('$(SolutionDir).nugetNuGet.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).nugetNuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir).nugetNuGet.targets'))" />
...
</Target>

这是MSBuild集成包还原脚手架的"不期望"行为。

我已经根据文档手动移除了这个脚手架,但当我将项目提交到构建服务器时,automaitc包恢复似乎会将脚手架添加回,导致构建失败。

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....nugetNuGet.targets.

当包中包含msbuild目标时,有人有办法阻止/阻止这个脚手架被包括在内吗?

更新

我尝试了一种变通方法来代替解决方案。也就是说,我创建了另一个nuget包来解决丢失的nuget.targets文件。当添加到项目中时,这个新包本身包括一个DependsOnTargetsEnsureNuGetPackageBuildImports的目标,并创建一个空白/有效的nuget.targets。这满足了从csproj脚手架触发的条件,同时允许在生成服务器上仍然触发nuget包自动还原功能。

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

解决方案所在的文件夹是否有.nuget文件夹?如果是,请尝试删除它。

我正在调整一个使用旧的(nuget 2.7之前)软件包恢复方式的解决方案,在删除该文件夹之前一直存在同样的问题。

最新更新