0
votes

I am in the early stages of migrating my codebase from .NET Framework to .NET Standard. I am converting some of the foundational projects in my solution to SDK Project types with target frameworks of net462 and netstandard2.0.

All of my applications and services are still .NET Framework.

To clarify, I have a library project targeting both frameworks, and then other library projects (.NET Framework only) that have the multi-target project as a reference, and then applications (.NET Framework only) that reference all of the above.

When I compile my solution in Visual Studio 2019, it compiles just fine. If I do a manual publish, that also works just fine. However, when I try to do a PR into Azure DevOps, my CI build pipeline errors with this error:

[error]C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.CrossTargeting.targets(27,5): Error : The 'Publish' target is not supported without specifying a target framework. The current project targets multiple frameworks, please specify the framework for the published application.

Google suggests that, if I were using dotnet -publish, I would need to provide a framework parameter. However the VSBuild task doesn't seem to support that.

The relevant YAML for my pipeline is:

steps:
- task: VSBuild@1
  displayName: 'Check for Build Errors'
  inputs:
    solution: '$(SolutionName)'
    msbuildArgs: '/target:publish'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    maximumCpuCount: true

And ideas or clarifying questions?

1

1 Answers

0
votes

Does specifying the MSBuild argument for the target framework in the msbuildArgs give you the results you're looking for?

    msbuildArgs: '/target:publish /p:TargetFramework=net462'

The reference for the dotnet msbuild command indicates the same MSBuild args are supported, and directs you (in a roundabout way 🙄) here, where you can see the monikers used for the different target frameworks.