dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.14k stars 4.71k forks source link

dotnet pack does not respect target framework conditions #77164

Closed paatrofimov closed 2 years ago

paatrofimov commented 2 years ago

Description

I have multitargeted csproj and I want to build and pack only the single target but dotnet pack always ignores passed configuration and packs all targets.

Reproduction Steps

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
        <Configurations>Net6;Netstandard20</Configurations>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)' == 'Net6'">
        <TargetFramework>net6.0</TargetFramework>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)' == 'Netstandard20'">
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

</Project>

The following command dotnet pack -c Netstandard20 results in error C:\Program Files\dotnet\sdk\6.0.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5026: The file 'E:\cm_1\drive\TestApp\bin\Netstandard20\net6.0\TestApp.dll' to be packed was not found on disk. [E:\cm_1\drive\TestApp\TestApp.csproj] because net6.0 configuration was not built and folder net6.0 is empty indeed.

I also tried to publish before packing (without build), but dotnet pack still does not seem to respect passed configuration.

  1. dotnet publish -c Netstandard20 - this command builds requested configuration and publishes it to bin\Netstandard20\netstandard2.0\publish.
  2. dotnet pack --no-build /p:OutputPath=bin\Netstandard20\netstandard2.0\publish\ - and this command produces nuget package which containts both folders lib\net6.0 and lib\netstandard2.0 with same published binaries which also looks incorrect since I wanted to publish and pack only netstandard2.0 configuration

Expected behavior

dotnet pack -c Netstandard20 to pack only the requested configuration and not try to do anything with the net6.0 target.

Actual behavior

dotnet pack -c Netstandard20 builds and packs all configurations listed in TargetFrameworks even though the following csproj conditions constrain the build only to the single target for passed configuration.

Regression?

No response

Known Workarounds

Can't figure out any, but would be glad if any would be suggested.

Configuration

No response

Other information

No response

ghost commented 2 years ago

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries See info in area-owners.md if you want to be subscribed.

Issue Details
### Description I have multitargeted csproj and I want to build and pack only the single target but `dotnet pack` always ignores passed configuration and packs all targets. ### Reproduction Steps ``` net6.0;netstandard2.0 Net6;Netstandard20 net6.0 netstandard2.0 ``` The following command `dotnet pack -c Netstandard20` results in error `C:\Program Files\dotnet\sdk\6.0.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5026: The file 'E:\cm_1\drive\TestApp\bin\Netstandard20\net6.0\TestApp.dll' to be packed was not found on disk. [E:\cm_1\drive\TestApp\TestApp.csproj]` because net6.0 configuration was not built and folder net6.0 is empty indeed. I also tried to publish before packing (without build), but dotnet pack still does not seem to respect passed configuration. 1. `dotnet publish -c Netstandard20` - this command builds requested configuration and publishes it to `bin\Netstandard20\netstandard2.0\publish`. 2. `dotnet pack --no-build /p:OutputPath=bin\Netstandard20\netstandard2.0\publish\` - and this command produces nuget package which containts both folders `lib\net6.0` and `lib\netstandard2.0` with same published binaries which also looks incorrect since I wanted to publish and pack only netstandard2.0 configuration ### Expected behavior `dotnet pack -c Netstandard20` to pack only the requested configuration and not try to do anything with the net6.0 target. ### Actual behavior `dotnet pack -c Netstandard20` builds and packs all configurations listed in TargetFrameworks even though the following csproj conditions constrain the build only to the single target for passed configuration. ### Regression? _No response_ ### Known Workarounds Can't figure out any, but would be glad if any would be suggested. ### Configuration _No response_ ### Other information _No response_
Author: paatrofimov
Assignees: -
Labels: `area-Infrastructure-libraries`
Milestone: -
ViktorHofer commented 2 years ago

Manually moved to NuGet: https://github.com/NuGet/Home/issues/12169.