Reputation: 807
I'm trying to figure out how to specify a packageId at build or specifically at package time. I have the following in my csproj which works well for creating packages locally for the purposes of testing. We are using Azure DevOps build pipelines to build and pack our nuget packages and I would like to be able to set the packageId as a task or msbuild parameter within the build pipeline.
Does anyone have suggestions on how I could acheive this?
Thanks,
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);Dependencies</TargetsForTfmSpecificBuildOutput>
<Version>0.1.0.5</Version>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyName>MyAssembly</AssemblyName>
<RootNamespace>MyAssembly</RootNamespace>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<PackageId>MyAssembly.Test</PackageId> <----- set at package time
<FileVersion>1.0.0.0</FileVersion>
<PackageLicenseUrl>https://my.domain.xyz/license.pdf</PackageLicenseUrl>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<Description>A useful description.</Description>
<Company>XYZ</Company>
<Authors>UiPath</Authors>
<PackageIconUrl>http://my.domain.xyz/favicon.ico</PackageIconUrl>
Upvotes: 1
Views: 2197
Reputation: 76910
Set PackageId at package time?
The answer is yes.
According to the document MSBuild pack target inputs, we could to know the PackageId
is supported to be set at build time.
Note:
I saw that you set the property GeneratePackageOnBuild
to true
, so visual studio will generate the nuget package automatically.
So, if you are not use extra dotnet pack
task to package your package, you add msbuild argument -p:PackageId=<PackageId>
with your dotnet build task, like:
dotnet build -c Release -p:PackageId=<PackageId>
If you have another dotnet pack
task to package your package, @Martin`s answer is correct.
Note2:
When we use the option -p:PackageId
to change the package ID, but the AssemblyName is not changed. So the Package ID
of the generated package is not consistent with its AssemblyName
. We need to pay more attention when we use this nuget package. Or we could also change the AssemblyName
to make it match the package id by the option -p:AssemblyName=<AssemblyName>
Hope this helps.
Upvotes: 3
Reputation: 100741
Did you try calling?:
dotnet pack -c Release -p:PackageId=The.Other.Packge.id
Or the equivalent in the .NET Core CLI task
Upvotes: 1
Reputation: 399
You could modify the XML of the csproj after clone and before build using the File Transform task:
Upvotes: 0