Using .NET Core 2.1
mkdir repro
cd repro
dotnet new console
Edit repro.csproj to add ServerGarbageCollection property:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>
</Project>
dotnet build
Open the repro.runtimeconfig.json:
{
"runtimeOptions": {
"tfm": "netcoreapp2.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "2.1.0"
}
}
}
It should have the System.GC.Server property:
"configProperties": {
"System.GC.Server": true
}
Running:
dotnet publish
Will produce the correct .runtimeconfig.json into the publish folder.
Had you run a build before and this was the only change you made to your project? We have tests covering this particular scenario, so I don't believe this has regressed.
We have had, though, for a while, an issue where incremental build checks are not triggering based on changes to this property. So, if you build, change just this property and build again, the runtimeconfig.json file won't be re-gerenerated.
I just tried this scenario and confirmed this is working as I described above. Changing the property, running dotnet clean and then dotnet build had the runtimeconfig.json generated properly.
I did a quick look and couldn't find the original issue though.
@dsplaisted @nguerrera would one of you remember this issue?
We should add a $(MSBuildAllProjects) input. This isn't perfect. It doesn't work with /p:ServerGarbageCollection changed between builds, but it fixes the repro here and many targets in msbuild use this heuristic. A few hash things to get more correcness, but that is painful.
Looks like past discussions were about deps file and we ended up adding $(MSbuildAllProjects) for that, but neglected to make the same change for runtime config.
Ah, that must have been what I was remembering. Let's use this bug to track this change for the runtime config then.
There are two separate issues here:
The one tracked by this bug, which is about the fact that runtime properties are not written to .runtimeconfig.json on .NET Core 2.1 (and probably 2.2). It works on 3.0. This is true even for clean/build. Basically this issue is about the discussion whether we can fix it for 2.* apps in some way.
The other problem is that changing settings which affect .runtimeconfig.json are not triggering rebuild of that file during incremental dotnet build. That issue is tracked by #2787 - or it seems so.
@vitek-karas I cannot reproduce the first issue.
Using .NET Core 2.1
This would be an SDK bug, so it would depend on the sdk version. Please supply dotnet --info.
I have tried the following script on every sdk on my machine:
@echo off
rd /s /q obj bin
dotnet new global.json --sdk-version %1 --force
dotnet --version
dotnet build /nologo /clp:NoSummary
findstr netcoreapp *.csproj
findstr GC bin\Debug\netcoreapp2.1\*.runtimeconfig.json
Here are the results:
D:\Temp\rc>repro.cmd 2.1.505
The template "global.json file" was created successfully.
2.1.505
Restoring packages for D:\Temp\rc\rc.csproj...
Generating MSBuild file D:\Temp\rc\obj\rc.csproj.nuget.g.props.
Generating MSBuild file D:\Temp\rc\obj\rc.csproj.nuget.g.targets.
Restore completed in 169.81 ms for D:\Temp\rc\rc.csproj.
rc -> D:\Temp\rc\bin\Debug\netcoreapp2.1\rc.dll
rc.csproj: <TargetFramework>netcoreapp2.1</TargetFramework>
bin\Debug\netcoreapp2.1\rc.runtimeconfig.json: "System.GC.Server": true
D:\Temp\rc>repro.cmd 2.1.602
The template "global.json file" was created successfully.
2.1.602
Restore completed in 139.4 ms for D:\Temp\rc\rc.csproj.
rc -> D:\Temp\rc\bin\Debug\netcoreapp2.1\rc.dll
rc.csproj: <TargetFramework>netcoreapp2.1</TargetFramework>
bin\Debug\netcoreapp2.1\rc.runtimeconfig.json: "System.GC.Server": true
D:\Temp\rc>repro.cmd 2.2.104
Getting ready...
The template "global.json file" was created successfully.
2.2.104
Restoring packages for D:\Temp\rc\rc.csproj...
Generating MSBuild file D:\Temp\rc\obj\rc.csproj.nuget.g.props.
Generating MSBuild file D:\Temp\rc\obj\rc.csproj.nuget.g.targets.
Restore completed in 176.19 ms for D:\Temp\rc\rc.csproj.
rc -> D:\Temp\rc\bin\Debug\netcoreapp2.1\rc.dll
rc.csproj: <TargetFramework>netcoreapp2.1</TargetFramework>
bin\Debug\netcoreapp2.1\rc.runtimeconfig.json: "System.GC.Server": true
D:\Temp\rc>repro.cmd 2.2.202
Getting ready...
The template "global.json file" was created successfully.
2.2.202
Restore completed in 157.93 ms for D:\Temp\rc\rc.csproj.
rc -> D:\Temp\rc\bin\Debug\netcoreapp2.1\rc.dll
rc.csproj: <TargetFramework>netcoreapp2.1</TargetFramework>
bin\Debug\netcoreapp2.1\rc.runtimeconfig.json: "System.GC.Server": true
D:\Temp\rc>repro.cmd 3.0.100-preview4-010907
Getting ready...
The template "global.json file" was created successfully.
3.0.100-preview4-010907
Persisting no-op dg to D:\Temp\rc\obj\rc.csproj.nuget.dgspec.json
Restore completed in 132.64 ms for D:\Temp\rc\rc.csproj.
C:\Program Files\dotnet\sdk\3.0.100-preview4-010907\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [D:\Temp\rc\rc.csproj]
rc -> D:\Temp\rc\bin\Debug\netcoreapp2.1\rc.dll
rc.csproj: <TargetFramework>netcoreapp2.1</TargetFramework>
bin\Debug\netcoreapp2.1\rc.runtimeconfig.json: "System.GC.Server": true
I've moved my comment on how to fix incrementality to https://github.com/dotnet/sdk/issues/2787 and put it in the 3.0 milestone. I've moved this back to Discussion milestone until I see an actual repro.
Sorry - I can't repro it either now.
I know I tried it several times yesterday, but now on the same machine it works just fine.
I guess I must have run into the incremental build issue without realizing it...
Sorry again for the confusion.
In version 3.1 it is still happening to me
If I first compile with "dotnet build" and later publish with "dotnet publish" with the parameter "-p: ServerGarbageCollection=false" the .runtimeconfig.json file contains the value "System.GC.Server: true"
On the other hand, if I do the "dotnet publish" with the parameter "-p: ServerGarbageCollection = false" from an empty compilation the value is "System.GC.Server: false"
That is, the dotnet publish with this parameter does not modify the .runtimeconfig.json file