Click here to Skip to main content
14,934,882 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
   
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.
PIEBALDconsult 11-Nov-20 10:31am
   
Maybe it isn't using either of those and is using only the defaults?
Mehdi Gholam 11-Nov-20 10:32am
   
Then how come when you set the debug config it works?
Mehdi Gholam 11-Nov-20 10:37am
   
dotnet build -c Release fastJSONCore.sln -v n
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 2020-11-11
     1>Project "xxxxxxxxxxxxx\fastJSONCore.sln" on node 1 (Restore target(s)).
     1>ValidateSolutionConfiguration:
         Building solution configuration "Release|Any CPU".
       _GetAllRestoreProjectPathItems:
         Determining projects to restore...
       Restore:
         Committing restore...
         Assets file has not changed. Skipping assets file writing. Path: xxxxxxxxxxxxx\fastJSONcore\obj\project.assets.json
         Restored xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj (in 30 ms).

         NuGet Config files used:
             C:\Users\mgholam\AppData\Roaming\NuGet\NuGet.Config
             C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

         Feeds used:
             https://api.nuget.org/v3/index.json
             C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
         All projects are up-to-date for restore.
     1>Done Building Project "xxxxxxxxxxxxx\fastJSONCore.sln" (Restore target(s)).
   1:2>Project "xxxxxxxxxxxxx\fastJSONCore.sln" on node 1 (default targets).
     1>ValidateSolutionConfiguration:
         Building solution configuration "Release|Any CPU".
   1:2>Project "xxxxxxxxxxxxx\fastJSONCore.sln" (1:2) is building "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (2:18) on node 1 (default targets).
  2:18>Project "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (2:18) is building "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (2:19) on node 3 (Build target(s)).
     2>GenerateTargetFrameworkMonikerAttribute:
       Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
  2:18>Project "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (2:18) is building "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (2:20) on node 2 (Build target(s)).
     2>GenerateTargetFrameworkMonikerAttribute:
       Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
       CoreCompile:
       Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
       CopyFilesToOutputDirectory:
         fastJSON -> xxxxxxxxxxxxx\output\net4\fastJSON.dll
     2>Done Building Project "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (Build target(s)).
     2>CoreCompile:
       Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
       GenerateBuildDependencyFile:
       Skipping target "GenerateBuildDependencyFile" because all output files are up-to-date with respect to the input files.
       CopyFilesToOutputDirectory:
         fastJSON -> xxxxxxxxxxxxx\output\net5.0\fastJSON.dll
     2>Done Building Project "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (Build target(s)).
  2:18>Project "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (2:18) is building "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (2:21) on node 1 (Build target(s)).
     2>GenerateTargetFrameworkMonikerAttribute:
       Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
       CoreCompile:
       Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
       GenerateBuildDependencyFile:
       Skipping target "GenerateBuildDependencyFile" because all output files are up-to-date with respect to the input files.
       CopyFilesToOutputDirectory:
         fastJSON -> xxxxxxxxxxxxx\output\netstandard2.0\fastJSON.dll
     2>Done Building Project "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj" (Build target(s)).
     2>Done Building Project "xxxxxxxxxxxxx\fastJSONcore\fastJSON.csproj"
Richard MacCutchan 12-Nov-20 5:27am
   
Try adding NDEBUG to the DefineConstants section of the release settings. No guarantee, but I know that is used in some project settings.
Mehdi Gholam 12-Nov-20 5:35am
   
nope, still the same.
Richard MacCutchan 12-Nov-20 5:36am
   
Yes, it was a long shot.
Mehdi Gholam 12-Nov-20 5:38am
   
I posted an issue to MS on github yesterday, waiting for a reply.
Richard MacCutchan 12-Nov-20 5:42am
   
Looking through the output above, I do not see any actual compilations taking place. Most items appear to be skipped as all files are up to date. Try changing some files or cleaning all the targets.
Mehdi Gholam 12-Nov-20 10:21am
   
Using the project file
dotnet build -c Release fastJSONCore.csproj
works!
Richard MacCutchan 12-Nov-20 10:30am
   
Well now you are the expert. :)
Mehdi Gholam 13-Nov-20 9:59am
   
Found the problem, posted the solution.

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
...
   
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