What's the difference between dotnet publish -c Release vs -c Debug?
-
Hi everyone, I'm building my personal web site using ASP.Net and recently noticed something curious. When publishing my project, it doesn't seem to matter if I use:
dotnet publish -c Release -o out
or
dotnet publish -c Debug -o out
Both commands will output (as far as I can tell) exactly the same binary. However shouldn't the release output be smaller/optimized? Unfortunately I can't find much documentation regarding this config flag and as far as I can tell, the dotnet command is just passing it along to MSBuild which then select the proper configuration (profile?). Does anyone know if it's supposed to work like that or am I doing something dumb? PS: My csproj has nothing special in it as far as I can tell:
net6.0 enable all runtime; build; native; contentfiles; analyzers; buildtransitive
-
Hi everyone, I'm building my personal web site using ASP.Net and recently noticed something curious. When publishing my project, it doesn't seem to matter if I use:
dotnet publish -c Release -o out
or
dotnet publish -c Debug -o out
Both commands will output (as far as I can tell) exactly the same binary. However shouldn't the release output be smaller/optimized? Unfortunately I can't find much documentation regarding this config flag and as far as I can tell, the dotnet command is just passing it along to MSBuild which then select the proper configuration (profile?). Does anyone know if it's supposed to work like that or am I doing something dumb? PS: My csproj has nothing special in it as far as I can tell:
net6.0 enable all runtime; build; native; contentfiles; analyzers; buildtransitive
The output is MSIL, not machine code native to your CPU. That doesn't get generated until the code is loaded and running, call JIT Compiling. The code can be optimized for the CPU being used. Whether or not there are optimizations depends on how you've written your code and the CPU you run it on. Debug builds do not run with optimizations, but contain more debugging information that may not be in the final executables.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
The output is MSIL, not machine code native to your CPU. That doesn't get generated until the code is loaded and running, call JIT Compiling. The code can be optimized for the CPU being used. Whether or not there are optimizations depends on how you've written your code and the CPU you run it on. Debug builds do not run with optimizations, but contain more debugging information that may not be in the final executables.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakThanks but in that case I don't understand what is the purpose of the --configuration flag? I understand that JIT will optimize things at runtime but I was expecting the --configuration to, at least, do some sort of (even if small) optimization when compiling (a la gcc compiling C code for example) to MSIL. Many tutorials (especially Microsoft) almost always add that flag when publishing so it must do something but I can't understand what exactly.
Quote:
Debug builds do not run with optimizations, but contain more debugging information that may not be in the final executables.
Yes this is exactly what I find confusing because my debug build doesn't have (as far as I can tell) any extra debugging information. It seems to be exactly the same as the release build (using -c Release)
-
Thanks but in that case I don't understand what is the purpose of the --configuration flag? I understand that JIT will optimize things at runtime but I was expecting the --configuration to, at least, do some sort of (even if small) optimization when compiling (a la gcc compiling C code for example) to MSIL. Many tutorials (especially Microsoft) almost always add that flag when publishing so it must do something but I can't understand what exactly.
Quote:
Debug builds do not run with optimizations, but contain more debugging information that may not be in the final executables.
Yes this is exactly what I find confusing because my debug build doesn't have (as far as I can tell) any extra debugging information. It seems to be exactly the same as the release build (using -c Release)
You're also assuming that your code has stuff to optimize.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
You're also assuming that your code has stuff to optimize.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakThat's actually a very good point now that you mentioned it. I didn't consider that and assumed that an ASP.Net app would be large enough to see some optimizations but I guess the libraries used are already optimized and my code doesn't have much stuff to optimize.