Msbuild: Ability to specify nuget sources in project file

Created on 27 Dec 2017  路  5Comments  路  Source: dotnet/msbuild

Nuget.config is a nice way to get the dependencies' sources checked into sources. In addition to that, command line utilities also provide a way of specifying dependencies.

nuget.exe way

nuget install System.IO.Compression.Brotli `
  -source https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json `
  -source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json `
  -output deps `
  -Prerelease

dotnet.exe way:

# add PackageReference to System.IO.Compression.Brotli in project file

dotnet restore  `
  --source https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json `
  --source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json `
  --packages deps

Would be nice if we can:

  • specify sources in the proj file, so we don't need to carry an additional nuget.config file
    xml <ItemGroup> <NugetPackageSource Include="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" /> <NugetPackageSource Include="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" /> <PackageReference Include="System.IO.Compression.Brotli" Version="0.1.0-e171226-3" /> </ItemGroup>
  • restore package using command-line:
    powershell msbuild /restore ` /p:nuget-source=https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json&nuget-source=https://dotnet.myget.org/F/dotnet-core/api/v3/index.json

Most helpful comment

The RestoreSources and RestoreAdditionalProjectSources properties may be what you are looking for
https://github.com/NuGet/Home/wiki/%5BSpec%5D-NuGet-settings-in-MSBuild

All 5 comments

The RestoreSources and RestoreAdditionalProjectSources properties may be what you are looking for
https://github.com/NuGet/Home/wiki/%5BSpec%5D-NuGet-settings-in-MSBuild

Thanks @dasMulli!

Is it also possible to set DefaultPushSource in a same manner? I couldn't find any reference to that. With dotnet-cli, it's dotnet nuget -s <MyURL> some.nupkg. Would be dazzling if we can define it in one place, in csproj.

You could open an issue on https://github.com/NuGet/Home/issues

Problem here would be that unlike restore, the push operation is performed on a .nupkg file and not as msbuild target in the project file so there is no csproj file involved.

Btw, you could also wrap the call into an msbuild target..

<PropertyGroup>
  <PushSource>SOME-URL</PushSource>
</PropertyGroup>

<Target Name="PackAndPush" DependsOnTargets="Pack">
  <Exec Command="dotnet nuget push -s $(PushSource) $(PackageOutputAbsolutePath)$(PackageId).$(PackageVersion).nupkg" />
</Target>

Which you can invoke via

> dotnet msbuild /t:PackAndPush /p:Configuration=Release

Thanks for the reference. I will move that issue to NuGet Home

Was this page helpful?
0 / 5 - 0 ratings