我想将我的小精灵恢复到一个新的水平。我的repo目录指向ex。 c:\ repo \ s和我的solutin在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包添加到项目时,它将在项目文件中添加以下代码以指定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
来提取程序包/ dll。正确的HintPath应该是:
<HintPath>..\..\packages\Newtonsoft.Json.12.0.3-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
这是msbuild无法从已还原位置选择软件包的原因。
要解决此问题,您需要在程序包管理器控制台中使用NuGet命令行(在本地VS上:
Update-Package -reinstall
强制将软件包引用重新安装到项目中,它将更新HintPath
。将更改文件上传到Azure devops并进行构建。
希望这会有所帮助。