In an C#
based project, I am using preview packages are are hosting on a nuget.cloudsmith.io
not nuget.org
. The production packages are hosted on nuget.org.
I want to define rules in my Nuget.config
file to restore preview packages from nuget.cloudsmith.io
but others from nuget.org
So any package id that starts with PackagePrefix.
and the version contains -preview-
should be downloaded from cloudsmith.io
. Any other package should be downloaded from nuget.org.
For example, the package PackagePrefix.SomeProject
with version 2.5.0
will be downloaded from nuget.org. But, The package PackagePrefix.SomeOtherProject
with version 2.6.0-preview-5
will be downloaded from cloudsmith.io
.
Here is what I have done. But I can't find a way to target package-id + version pattern. I tried to map using <package pattern="PackagePrefix.*" version="*-preview-*" />
but this does not seems to be working.
<?xml version="1.0" encoding="utf-8"?><configuration><packageSources><clear /><add key="nuget.org" value="https://api.nuget.org/v3/index.json" /><add key="cloudsmith.io" value="https://nuget.cloudsmith.io/PackagePrefix/preview/v3/index.json" /></packageSources><packageSourceMapping><!-- key value for <packageSource> should match key values from <packageSources> element --><packageSource key="nuget.org"><package pattern="*" /></packageSource><packageSource key="cloudsmith.io"><package pattern="PackagePrefix.*" version="*-preview-*" /></packageSource></packageSourceMapping></configuration>
Here is the warning I get when trying to build a project
warning NU1507: There are 2 package sources defined in your configuration. When using central package management, please map your package sources with package source mapping (https://aka.ms/nuget-package-source-mapping) or specify a single package source. The following sources are defined: nuget.org, cloudsmith.io
How can I map a package using package id and package version to a specific source?