Click here to Skip to main content
15,436,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following project file :
XML
...
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <DefineConstants>TRACE;DEBUG;NETSTANDARD2_0; NET4;</DefineConstants>
        <OutputPath>..\output\</OutputPath>
        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
        <Optimize>false</Optimize>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
        <DefineConstants>NETSTANDARD2_0; NET4;</DefineConstants>
        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
        <Optimize>true</Optimize>
        <OutputPath>..\output\</OutputPath>
    </PropertyGroup>
...

When running the following command :
dotnet build -c Release proj.sln

The optimize property is not used and is as if the Debug configuration is used.

What I have tried:

The only way is setting the <Optimize>true</Optimize> in the debug config, which defeats the purpose of it.
Posted
Updated 13-Nov-20 3:56am
Comments
CHill60 11-Nov-20 9:26am    
I don't follow you - how are you determining that it "is as if the Debug configuration is used" and the only way to what is setting optimize true in the debug config - surely that does nothing to the Release config at all?? Do you get the same problem with dotnet publish?
Mehdi Gholam 11-Nov-20 9:28am    
The output file sizes differ (smaller) with optimize on.
PIEBALDconsult 11-Nov-20 10:22am     CRLF
Not necessarily. Perhaps it's also including debug info? You can have both optimized and full debug info, they are not mutually exclusive.
Mehdi Gholam 11-Nov-20 10:23am    
The execution is also slower.
PIEBALDconsult 11-Nov-20 10:26am    
Then perhaps you have other issues.

1 solution

Finally found the problem, in your solution file you should configure the ProjectConfigurationPlatforms section to build Release and not Debug when the active configuration is set.
XML
...
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{32DBA62B-6F46-423F-9A2E-05CF451B0BAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{32DBA62B-6F46-423F-9A2E-05CF451B0BAD}.Debug|Any CPU.Build.0 = Debug|Any CPU

		{32DBA62B-6F46-423F-9A2E-05CF451B0BAD}.Release|Any CPU.ActiveCfg = Release|Any CPU  <!-- here -->
		{32DBA62B-6F46-423F-9A2E-05CF451B0BAD}.Release|Any CPU.Build.0 = Release|Any CPU  <!-- here -->
	EndGlobalSection
...
 
Share this answer
 
v3
Comments
Richard MacCutchan 13-Nov-20 10:01am    
They do like to make it easy don't they?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900