0
$\begingroup$

I'm creating a NuGet package in an Azure DevOps pipeline from a multi-targeted .NET library that targets .NET Standard 2.0 and .NET 4.5. The pipeline sets the version dynamically using a variable (PackageVersion, e.g., 1.1.9 or 1.1.9-preview), like this:

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: $(csprojFilePath)

- task: DotNetCoreCLI@2
  displayName: dotnet build
  inputs:
    command: 'build'
    projects: $(csprojFilePath)
    arguments: '--configuration $(BuildConfiguration) --no-restore /p:Version=$(PackageVersion) /p:InformationalVersion=$(PackageVersion)'

- task: DotNetCoreCLI@2
  displayName: dotnet pack
  inputs:
    command: 'pack'
    packagesToPack: $(csprojFilePath)
    versioningScheme: 'byEnvVar'
    versionEnvVar: 'PackageVersion'

Inside the .csproj I have:

<PropertyGroup>
  <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
  <Version>0.0.1-preview</Version>
  <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

After the pipeline runs, the resulting .nupkg contains two DLLs — one for each target framework.

The .NET 4.5 DLL correctly has the overridden version set by the pipeline (e.g., 1.1.10-preview) in its AssemblyVersion, FileVersion, and InformationalVersion.

The .NET Standard 2.0 DLL still contains the default version from the .csproj file in all its version fields.

The package manifest (.nuspec) shows the correct version, but the compiled DLL for .NET Standard 2.0 does not reflect the overridden values.

.NET 4.5:

Screenshot of the lib\net45 DLL inside the NuGet package, showing that AssemblyFileVersion, AssemblyInformationalVersion, and the assembly's full name all correctly reflect the pipeline-defined version 1.1.8-preview

.NET Standard 2.0:

Screenshot of the lib\netstandard2.0 DLL inside the same NuGet package, showing that AssemblyFileVersion, AssemblyInformationalVersion, and the assembly's full name still reflect the default value 0.0.1-preview from the .csproj, ignoring the pipeline-defined version

Is there anything else I need to configure to ensure the version override applies to all target frameworks?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.