Nuget有规则来定位要使用的nuget.config文件。
在大型/复杂的monorepo中,文件不一定位于工作区/解决方案"root“。
是否有一个shell命令来确定nuget已经选择并将用于nuget操作的nuget.config文件?
(我找到的最接近的东西是dotnet nuget list source,但这并不能告诉我选择了哪个文件。)
发布于 2022-08-22 07:35:06
我没有找到一个命令直接回答你的问题。但是,在运行dotnet restore -f -v n时,它提供了以下输出:
Build started 22.08.2022 08:58:38.
1>Project "C:\source\temp\NuGetTest2\NuGetTest2.sln" on node 1 (Restore target(s)).
1>ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
_GetAllRestoreProjectPathItems:
Determining projects to restore...
Restore:
Restoring packages for C:\source\temp\NuGetTest2\src\Test\Test.csproj...
Assets file has not changed. Skipping assets file writing. Path: C:\source\temp\NuGetTest2\src\Test\obj\project.assets.json
Restored C:\source\temp\NuGetTest2\src\Test\Test.csproj (in 373 ms).
NuGet Config files used:
C:\source\temp\NuGetTest2\src\Test\NuGet.Config
C:\source\temp\NuGetTest2\src\NuGet.Config
C:\source\temp\NuGetTest2\NuGet.Config
C:\Users\myUser\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
https://apiC.nuget.org/v3/index.json
1>Done Building Project "C:\source\temp\NuGetTest2\NuGetTest2.sln" (Restore target(s)).由于使用了apiC,我假设输出的顺序等同于优先级。这些是我的NuGet.Config文件:
NuGet.Config<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGetA" value="https://apiA.nuget.org/v3/index.json" />
</packageSources>
</configuration>src\NuGet.Config<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGetB" value="https://apiB.nuget.org/v3/index.json" />
</packageSources>
</configuration>src\Test\NuGet.Config<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGetC" value="https://apiC.nuget.org/v3/index.json" />
</packageSources>
</configuration>发布于 2022-08-22 08:17:43
被接受的答案解释了这一方法。
如果你想要一条bash单线的话:
dotnet restore -v n | sed -n '/NuGet Config files used:/,/nuget.config/p' | tail -n-1 | xargs printf '%s\n'https://stackoverflow.com/questions/73431428
复制相似问题