yaml - msbuild 没有从恢复的位置挑选包
问题描述
我想将我的 nugets 恢复一级。我的 repo 目录指向 ex。c:\repo\s 并且我的解决方案在 c:\repo\s\src 中,当我使用 nuget restore 恢复包时,它在 C:\repo\s\src\packages 恢复包,我希望是 C:\repo\s\packages。感谢你的帮助。
我在 C:\repo\s\src 目录中有以下 nuget.config 文件。
$<configuration>
<config>
<add key="repositoryPath" value="..\..\packages" />
</config>
</configuration>
我的 Yaml 工作看起来像这样
$steps:
- task: NuGetToolInstaller@0
displayName: 'Use NuGet 4.3.0'
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
restoreSolution: src/myproject.sln
vstsFeed: '4448b1e2-8ac8-45ef-870c-1ebab90f3348'
restoreDirectory: '$(Build.SourcesDirectory)'
- task: VSBuild@1
displayName: 'Build solution src/myproject.sln'
inputs:
solution: src/myproject.sln
vsVersion: 15.0
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
解决方案
msbuild 没有从恢复的位置挑选包
无论是使用nuget.config
文件还是直接restoreDirectory: '$(Build.SourcesDirectory)'
在nuget restore
任务中指定,nuget都会将包还原到文件夹C:\repo\s\packages
中。
但是,NuGet 还原仅将包还原到还原目录,而不会修改您的项目文件。
当我们将nuget包添加到项目中时,它会在项目文件中添加以下代码来指定dll位置:
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
有节点HintPath
指定dll文件的位置。
当我们使用nuget.config
或restoreDirectory: '$(Build.SourcesDirectory)'
更改包还原的位置时,MSBuild 不会拾取基于 HintPath
. 正确的 HintPath 应该是:
<HintPath>..\..\packages\Newtonsoft.Json.12.0.3-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
这就是为什么 msbuild 没有从恢复的位置挑选包的原因。
要解决此问题,您需要在包管理器控制台中使用 NuGet 命令行(在本地 VS 上):
Update-Package -reinstall
要强制将包引用重新安装到项目中,它将更新HintPath
. 将更改文件上传到 Azure devops 并构建它。
希望这可以帮助。
推荐阅读
- html - 如何让我的搜索栏在 html 中变大?
- django - 如何使用 TemplateHTMLRenderer 在 Django-REST-Framework 中创建/放置?
- java - 从在线托管的 mysql 数据库中检索数据的最快方法是什么?
- c# - ASP.NET HttpPost 方法。无法正确接收数据
- shell - 如何将文件从一台服务器直接下载到另一台服务器?
- c# - 如何从其视图模型中关闭用户控件
- python - 使用 Python/Matplotlib 的 3D 图的限制
- java - Elasticsearch Java REST 客户端:查看符合条件的命中数是否超过 SearchSourceBuilder 大小
- php - 在 laravel 问题中通过复选框获取数据
- mysql - SQL Query 未返回所需结果且 NOT LIKE