Automate publishing a project's NuGet package during build process.
To use the package, you need to add the SS.NuGet.Publish NuGet package to your project. Then configure accordingly in the .csproj file.
- NuGetPublishVersion (Optional)
- Version of Nuget.exe to use. Defaults to 6.8.0
- NuGetPublishPath (Optional)
- Path to cache the Nuget.exe locally. Defaults to %UserProfile%\.nuget\{NuGetPublishVersion}\
- NuGetPublishType (Optional)
- Either remote or local. Will try to auto detect if NuGetPublishLocation is a url (begins with http), defaults to local if NuGetPublishLocation is not a url.
- NuGetPublishLocation
- Valid URL or path to publish the NuGet package to
- NuGetPublishSkipDuplicate
- Set to true to add the
-SkipDuplicatecommand line option for nuget push command.
- Set to true to add the
- If not already cached, it will download a copy of nuget.exe from https://dist.nuget.org/win-x86-commandline/v{NuGetPublishVersion}/nuget.exe into
NuGetPublishPath - Publish
- If
NuGetPublishType = remoteORNuGetPublishLocationstarts with http, it executes nuget.exe using push command toNuGetPublishLocationas the source - If
NuGetPublishType = localORNuGetPublishLocationdoes not start with http, it executes nuget.exe using add command toNuGetPublishLocationas the source - Manually setting
NuGetPublishTypedisables the auto-detection of publishing type.
- If
Note:
IfNuGetPublishLocationis not defined, no publish is attempted.
IfNuGetPublishTypeis set to remote, thenNuGetPublishLocationmust be a valid URL to a NuGet repo.
IfNuGetPublishTypeis set to local, thenNuGetPublishLocationmust be a valid local folder or UNC path.
If you're publishing to a remote site, like NuGet.org, you will need to set your API Key prior to publishing. Follow the instructions here to learn how to accomplish this.
<PropertyGroup>
<NuGetPublishType>remote</NuGetPublishType>
<NuGetPublishLocation>https://api.nuget.org/v3/index.json</NuGetPublishLocation>
</PropertyGroup><Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NuGetPublishLocation>D:\references\packages</NuGetPublishLocation>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NuGetPublishType>remote</NuGetPublishType>
<NuGetPublishLocation>https://api.nuget.org/v3/index.json</NuGetPublishLocation>
</PropertyGroup>
</project>