msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

dotnet publish uses debug configuration even if publishprofile has config=release

Open vpenades opened this issue 1 year ago • 14 comments

Issue Description

When publishing a project that has a publsh profile using Release, the program is being compiled in debug mode.

Steps to Reproduce

I have a project that has this publish profile:

<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Publish</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <_TargetId>Folder</_TargetId>
    <TargetFramework>net6.0-windows</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>false</SelfContained>
    <PublishSingleFile>true</PublishSingleFile>
    <PublishReadyToRun>false</PublishReadyToRun>
  </PropertyGroup>
</Project>

And I publish the project using command line:

dotnet publish -p:PublishProfile=FolderProfile project.csproj

I assumed that, because the publish profile has RELEASE configuration, it's the configuration used for building the project.

but I have this code:

#if DEBUG
Console.WriteLine("Running in DEBUG");
#endif

Which is, unexpectedly, executed when I run the program.

If I publish the project using this command line:

dotnet publish -p:PublishProfile=FolderProfile -c:Release project.csproj

Everything is fine.

So, what I don't understand is why, if the publish profile already has a Release configuration, why it's also needed by the command line.

Expected Behavior

Having Release configuration in the publish profile should be enough for dotnet to run a Release build.

Actual Behavior

If the command line does not have '-c:Release' even if publish profile already has it, the program is built using Debug mode.

Versions & Configurations

SBuild version 17.3.1+2badb37d1 for .NET Framework 17.3.1.41501

dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.401 Commit: 0906eae6f8

vpenades avatar Sep 15 '22 09:09 vpenades

@nagilson can you take a look at this publish profile issue?

rainersigwald avatar Sep 15 '22 14:09 rainersigwald

Definitely, I'll take a look into why this is happening.

nagilson avatar Sep 15 '22 16:09 nagilson

Configuration is being set to Release by the Publish Profile but this looks like the same nonsense as the PublishRelease fiasco where it doesn't get imported early enough, so DebugSymbols and OutputPath, etc, are set to the wrong value.

nagilson avatar Sep 15 '22 19:09 nagilson

@rainersigwald It's likely we could solve it in a similar way to how PublishRelease works, though that'd only take effect in the CLI and be kinda gross. An alternative is if we can make publish profiles basically the first or close to first thing that gets done in evaluation, which may have an impact on design time builds or something akin to that. We should discuss this further.

nagilson avatar Sep 15 '22 21:09 nagilson