Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet publish should default to release mode #10357

Closed
benaadams opened this issue Jun 29, 2019 · 25 comments
Closed

dotnet publish should default to release mode #10357

benaadams opened this issue Jun 29, 2019 · 25 comments
Assignees
Milestone

Comments

@benaadams
Copy link
Member

benaadams commented Jun 29, 2019

Currently it defaults to debug (bad for performance of deployed sites, libraries put on nuget, and apps)

While this is obvious when using dotnet publish without parameters as it puts it in a Debug folder; it is not obvious when using an output setting as it is put in the output directory without an obvious Debug moniker

@livarcocc
Copy link
Contributor

@KathleenDollard to consider this breaking change.

@forki
Copy link

forki commented Jun 29, 2019 via email

@benaadams
Copy link
Member Author

Was pointed out pre-1.0 that this was incorrect behaviour https://github.com/dotnet/cli/issues/477 however the issue was closed but not fixed

There are number of examples of people putting Debug builds into production and Debug libs onto NuGet

@nguerrera
Copy link
Contributor

nguerrera commented Jun 29, 2019

This is not as simple as it might seem.

dotnet publish doesn't explicitly set the configuration to Debug. It just does what msbuild /t:Publish does without a /p:Configuration=X argument. That is not necessarily debug: try it with a Directory.Build.props like this:

<Project>
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
  </PropertyGroup>
</Project>

Further note that configurations can be arbitrarily customized. There might not even be one called Release in the project. Forcing /p:Configuration=Release by default is most definitely a breaking change. It might not even work. Or it might override to a less efficient configuration than a custom configuration that is not named Release and made to be the default in project code like above. And even when it works, it will certainly break cases where people are relying on getting Debug in the case where they have not passed an explicit configuration.

Microsoft.NET.Sdk chooses Debug by default here:

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

This applies to more than publish, and like so many other things in those props, it maps to what got spelled out in File -> New in classic projects. Breaking with that ancient tradition will likely have other unintended consequences.

@benaadams
Copy link
Member Author

Perhaps a more general way of capturing the requirement is dotnet publish should default to optimized output if it is not overriden.

@nguerrera
Copy link
Contributor

There are a lot of different ways to interpret that requirement.

My above comment demonstrates why changing dotnet publish to be equivalent to today’s dotnet publish -c Release is very problematic, technically.

It’s certainly possible that a more involved change could work. We’d need a concrete proposal to evaluate that.

@benaadams
Copy link
Member Author

benaadams commented Jun 29, 2019

Microsoft.NET.Sdk chooses Debug by default here:

Can publish and build/run be differentiated and the default swapped for publish?

@nguerrera
Copy link
Contributor

Possibly. We could set /p:RunningDotNetPublishWithDefaultConfig=true. And change above based on that. Or something. It would mean that dotnet publish and msbuild /t:Publish are different, though.

@benaadams
Copy link
Member Author

It would mean that dotnet publish and msbuild /t:Publish are different, though.

Solving the compat worries in one fell swoop! 😉

Also I hear there's a major version (this and the next) which would be an ideal time for such a change 😄

@nguerrera
Copy link
Contributor

Just to set expectations, I think we’re way too late for 3, but happy to explore this for 5.

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the Discussion milestone Jan 31, 2020
@benaadams
Copy link
Member Author

Can this be done for 5.0?

@benaadams
Copy link
Member Author

but happy to explore this for 5.

@nguerrera @KathleenDollard any news?

@forki
Copy link

forki commented Aug 14, 2020

Thanks for still pushing them to do the right thing Ben

@benaadams
Copy link
Member Author

Recent example of someone having performance issues from not publishing in release mode #12834

@nguerrera
Copy link
Contributor

nguerrera commented Aug 14, 2020

@benaadams Sorry, I don’t work on this project or .NET anymore. It’s been five months since I left so I don’t know if there’s been any development on this.

@richlander
Copy link
Member

We're going to take another (and hopefully final) run at resolving this for .NET 6.0.

@forki
Copy link

forki commented Aug 14, 2020

Lol

@tmds
Copy link
Member

tmds commented Nov 26, 2020

<Project>
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
  </PropertyGroup>
</Project>

I guess there is no way to set this conditionally based on the target because there is no property that describes the targets that are being built/requested?

@DanielHabenicht
Copy link

@richlander here we are, shortly before 6.0 release (no pressure 😄)

@forki
Copy link

forki commented Oct 28, 2021

moving-goalpost

@EskeRahn
Copy link

A little late to the party, but one could say that the issue here is semantics causing confusion.
With "publish" one sort of intuitively expect that it is actually about publishing. And not about producing code for debugging.

But taking a step backwards this also should match msbuild.

Perhaps the clean way would be to always have a default release path as well as the default debug path, and to define two new keywords for compiling to debug and to release. And have "publish" deprecated but mirroring the debug for backwards compatibility. Perhaps simply something like todebug and torelease?
And if people have multiple configuration profiles obviously allow us to pick a specific one by name

@richlander
Copy link
Member

FYI: #23551

@dsplaisted
Copy link
Member

We think that we can do this for projects that target .NET 8 or higher, by setting the PublishRelease property to true (if not already set) in the .NET SDK targets if the project targets .NET 8 or higher.

@dsplaisted
Copy link
Member

This is done and can be closed, right @nagilson?

@nagilson
Copy link
Member

nagilson commented Mar 2, 2023

That's correct. We've changed the default to Release for 8.0+ TFMS: #29155 ( as well as for pack.)

Was waiting for the release so there were no more 🥅 ;)

@nagilson nagilson closed this as completed Mar 2, 2023
@nagilson nagilson self-assigned this Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests