Nuget 未安装在 Azure DevOps 构建中
Nuget not installing in Azure DevOps build
我正在尝试停止将来自 Nuget 包的任何内容存档到代码源存储库中。对于大多数人来说,因为他们只有 dll,所以它可以工作。
我的问题是我在 nupkg 中有一个带有 Content
文件夹的 Nuget。使用 VS2017 进行构建时,所有内容均已正确安装,但使用构建服务器(Azure DevOps 管道)执行相同操作时,我得到
Error MSB3030: Could not copy the file "....." because it was not found.
根据Capabilities,管道代理版本是v.2.122.1。
NuGet 任务使用 NuGet 3.3.0.212 和 MsBuild 14.0 记录版本 0.2.31。
我在 packages
文件夹中看到了 nupkg 文件,但是 Content
文件夹项目没有被复制。
我是否需要向我的 csproj 添加任何特殊内容或我应该向我的构建定义添加任何其他步骤?
Is there anything special I need to add to my csproj or any additional steps I should add to my build definition?
您需要将 csproj 文件更改为 link 内容包中的文件,而不是将文件添加到项目中。由于您试图停止将来自 Nuget 包的任何内容归档到代码源存储库中,因此请将 nuget restore 任务添加到您的构建定义中。
作为测试,我创建了一个内容包并添加了一个复制事件以从内容包中复制文件:
安装该包后,项目文件.csproj
和packages.config
中将添加以下内容:
.csproj:
<ItemGroup>
<Content Include="resources\Test.txt" />
<Content Include="resources\Test2.txt" />
</ItemGroup>
Packages.config:
<packages>
<package id="TestContentPackage" version="1.0.0" targetFramework="net461" />
</packages>
然后 我们将 .csproj
文件更改为 link 内容包中的文件:
<ItemGroup>
<Content Include="..\Packages\TestContentPackage.1.0.0\content\resources\Test.txt" />
<Content Include="..\Packages\TestContentPackage.1.0.0\content\resources\Test2.txt" />
</ItemGroup>
更改后,内容包中的文件不会添加到项目中,只是link添加到项目中:
为了验证复制命令,我在构建事件中添加了以下复制命令:
if not exist $(ProjectDir)TestFolder mkdir $(ProjectDir)TestFolder
xcopy /y "$(SolutionDir)Packages\TestContentPackage.1.0.0\content\resources\Test2.txt" "$(ProjectDir)TestFolder"
我本地的一切正常。
然后我用 Azure devops 构建这个项目,你需要添加 nuget 还原任务,否则,Visual Studio/MSBuild 无法从包中找到文件。而且它也很好用。
注意:如果要从content文件夹中复制文件,需要从packages
文件夹中复制。
希望这对您有所帮助。
我正在尝试停止将来自 Nuget 包的任何内容存档到代码源存储库中。对于大多数人来说,因为他们只有 dll,所以它可以工作。
我的问题是我在 nupkg 中有一个带有 Content
文件夹的 Nuget。使用 VS2017 进行构建时,所有内容均已正确安装,但使用构建服务器(Azure DevOps 管道)执行相同操作时,我得到
Error MSB3030: Could not copy the file "....." because it was not found.
根据Capabilities,管道代理版本是v.2.122.1。 NuGet 任务使用 NuGet 3.3.0.212 和 MsBuild 14.0 记录版本 0.2.31。
我在 packages
文件夹中看到了 nupkg 文件,但是 Content
文件夹项目没有被复制。
我是否需要向我的 csproj 添加任何特殊内容或我应该向我的构建定义添加任何其他步骤?
Is there anything special I need to add to my csproj or any additional steps I should add to my build definition?
您需要将 csproj 文件更改为 link 内容包中的文件,而不是将文件添加到项目中。由于您试图停止将来自 Nuget 包的任何内容归档到代码源存储库中,因此请将 nuget restore 任务添加到您的构建定义中。
作为测试,我创建了一个内容包并添加了一个复制事件以从内容包中复制文件:
安装该包后,项目文件.csproj
和packages.config
中将添加以下内容:
.csproj:
<ItemGroup>
<Content Include="resources\Test.txt" />
<Content Include="resources\Test2.txt" />
</ItemGroup>
Packages.config:
<packages>
<package id="TestContentPackage" version="1.0.0" targetFramework="net461" />
</packages>
然后 我们将 .csproj
文件更改为 link 内容包中的文件:
<ItemGroup>
<Content Include="..\Packages\TestContentPackage.1.0.0\content\resources\Test.txt" />
<Content Include="..\Packages\TestContentPackage.1.0.0\content\resources\Test2.txt" />
</ItemGroup>
更改后,内容包中的文件不会添加到项目中,只是link添加到项目中:
为了验证复制命令,我在构建事件中添加了以下复制命令:
if not exist $(ProjectDir)TestFolder mkdir $(ProjectDir)TestFolder
xcopy /y "$(SolutionDir)Packages\TestContentPackage.1.0.0\content\resources\Test2.txt" "$(ProjectDir)TestFolder"
我本地的一切正常。
然后我用 Azure devops 构建这个项目,你需要添加 nuget 还原任务,否则,Visual Studio/MSBuild 无法从包中找到文件。而且它也很好用。
注意:如果要从content文件夹中复制文件,需要从packages
文件夹中复制。
希望这对您有所帮助。