Conversation
This changes the C# compiler so that it multi-targets between `netstandard2.0` and `netcoreapp3.1`.
|
Signed build validation is here https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=3439702&view=results |
|
@dotnet/roslyn-compiler PTAL |
Dismissing as signed build validation for this change has completed here https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=3439702&view=results
| --> | ||
| <UserRuntimeConfig Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(OutputType)' == 'Exe'">$(RepositoryEngineeringDir)config\runtimeconfig.template.json</UserRuntimeConfig> | ||
|
|
||
| <DisableNullableWarnings Condition="'$(DisableNullableWarnings)' == '' AND '$(TargetFramework)' != '' AND '$(TargetFramework)' == 'netcoreapp3.1'">true</DisableNullableWarnings> |
There was a problem hiding this comment.
Why is the second clause in the AND necessary? It would seem if the third clause (it's netcoreapp3.1) is true, the second is implied.
My question here is of course rooted in a deep mistrust of MSBuild and TFMs, so it wouldn't surprise me in the slightest if you tell me about something evil going on. But maybe that needs a comment then.
There was a problem hiding this comment.
Why is the second clause in the AND necessary? It would seem if the third clause (it's netcoreapp3.1) is true, the second is implied.
In a multi-targetted build this file gets evaluated three times: once in the outer build where only $(TargetFrameworks) is defined and twice for each $(TargetFramework) value. Need the middle clause so we don't set the property on the outer evaluation.
Welcome to one hour of my life that I lost here ...
There was a problem hiding this comment.
'$(TargetFramework)' != '' AND '$(TargetFramework)' == 'netcoreapp3.1'
This is an A && B scenario, where B implies A. It's possible the condition isn't written the expected way, because as-is the '$(TargetFramework)' != '' is unnecessary.
There was a problem hiding this comment.
Blarg I checked in a hack I was validiting locally with. Just a sec.
There was a problem hiding this comment.
The new warning check is the correct (albeit strange at a glance) one
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup Condition="'$(DisableNullableWarnings)' == 'true'"> | ||
| <NoWarn>$(NoWarn);8600;8601;8602;8603;8604;8605;8610;8616;8617;8714</NoWarn> |
There was a problem hiding this comment.
If/when the compiler adds another one, will we remember to update this?
There was a problem hiding this comment.
We'll find out the moment we get a warning in a netstandard2.0 build.
I don't know of a better way to manage this. Defining this property has made me re-think how we use our overall <Nullable> property though. Outside that though I think this is the best approach.
There was a problem hiding this comment.
The alternative, which is perhaps better, is what winforms is using. Define Nullable=enable for the project and add #nullable disable to all files. Then remove that from each file to enable it. With that approach, we could set Nullable=annotations for the netstandard2.0 build, Nullable=enable for the netcoreapp3.1 build.
There was a problem hiding this comment.
I'd rather maintain a simple warning set than modify every file and project in our repo
There was a problem hiding this comment.
That or change the compiler to hold a property in our targets files that listed every nullable warning.
Either way seems like this is a feature that would be generally valuable in compilation.
There was a problem hiding this comment.
@jcouv reminded me that this could be simplified to use the Nullable warning item and remove the individual code listing. Updated the PR
| </PackageDescription> | ||
|
|
||
| <!-- Disable the nullable warnings when compiling for netcoreapp3.1 during our transition period --> | ||
| <DisableNullableWarnings Condition="'$(TargetFramework)' == 'netcoreapp3.1'" /> |
There was a problem hiding this comment.
Isn't this going to fight with your other property in the Imports.targets?
There was a problem hiding this comment.
It's meant to fight with that. Specifically for the moment we want the inverse of the default: warn on netstandard2.0 not netcoreapp3.1. That's becuase there are a host of new warnings to work through. Once we fix all those we'll delete this property.
This property set is off though, need to explicitly set to true.
| <CoreClrCompilerBinArtifact Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.CSharp\$(Configuration)\netcoreapp3.1\Microsoft.CodeAnalysis.CSharp.dll" /> | ||
| <CoreClrCompilerBinArtifact Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.CSharp\$(Configuration)\netcoreapp3.1\**\Microsoft.CodeAnalysis.CSharp.resources.dll" /> | ||
|
|
||
| <CoreClrCompilerBinArtifact Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.VisualBasic\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.VisualBasic.dll" /> |
There was a problem hiding this comment.
Not moving VB along as well?
There was a problem hiding this comment.
VB is blocked until this issue is fixed dotnet/sdk#10591
|
@dotnet/roslyn-compiler can I get a review on this? It's mostly an infra change but I did have to change part of the compiler here to account for types like |
| --> | ||
| <UserRuntimeConfig Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(OutputType)' == 'Exe'">$(RepositoryEngineeringDir)config\runtimeconfig.template.json</UserRuntimeConfig> | ||
|
|
||
| <DisableNullableWarnings Condition="'$(DisableNullableWarnings)' == '' AND '$(TargetFramework)' != '' AND '$(TargetFramework)' != 'netcoreapp3.1'">true</DisableNullableWarnings> |
There was a problem hiding this comment.
Given how many people that confused, perhaps this is worth a comment.
| <!-- Bypass a check in msbuild that .NET Framework 3.5 is installed on the machine when targeting .NET < 4.0 --> | ||
| <BypassFrameworkInstallChecks>true</BypassFrameworkInstallChecks> | ||
| </PropertyGroup> | ||
| </PropertyGroup> |
333fred
left a comment
There was a problem hiding this comment.
LGTM (commit 6) with a couple small suggestions.
|
The roslyn integration tests are failing every where right now. I did run the MSBuild integration tests locally on my change and they passed. There was one failure but it was due to me not having the 4.5 targets installed. Going to go ahead and merge. |
This changes the C# compiler so that it multi-targets between
netstandard2.0andnetcoreapp3.1.