Skip to content

Multi-target C# compiler#41370

Merged
jaredpar merged 7 commits intodotnet:masterfrom
jaredpar:mt
Feb 6, 2020
Merged

Multi-target C# compiler#41370
jaredpar merged 7 commits intodotnet:masterfrom
jaredpar:mt

Conversation

@jaredpar
Copy link
Copy Markdown
Member

@jaredpar jaredpar commented Feb 3, 2020

This changes the C# compiler so that it multi-targets between
netstandard2.0 and netcoreapp3.1.

This changes the C# compiler so that it multi-targets between
`netstandard2.0` and `netcoreapp3.1`.
333fred
333fred previously requested changes Feb 3, 2020
Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preventing merge until signed build is completed.

@jaredpar
Copy link
Copy Markdown
Member Author

jaredpar commented Feb 4, 2020

@jaredpar jaredpar marked this pull request as ready for review February 4, 2020 07:04
@jaredpar jaredpar requested review from a team as code owners February 4, 2020 07:04
@jaredpar
Copy link
Copy Markdown
Member Author

jaredpar commented Feb 4, 2020

@dotnet/roslyn-compiler PTAL

@jaredpar jaredpar dismissed 333fred’s stale review February 4, 2020 07:05

Dismissing as signed build validation for this change has completed here https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=3439702&view=results

Comment thread eng/targets/Imports.targets Outdated
-->
<UserRuntimeConfig Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(OutputType)' == 'Exe'">$(RepositoryEngineeringDir)config\runtimeconfig.template.json</UserRuntimeConfig>

<DisableNullableWarnings Condition="'$(DisableNullableWarnings)' == '' AND '$(TargetFramework)' != '' AND '$(TargetFramework)' == 'netcoreapp3.1'">true</DisableNullableWarnings>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'$(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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blarg I checked in a hack I was validiting locally with. Just a sec.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new warning check is the correct (albeit strange at a glance) one

Comment thread eng/targets/Imports.targets Outdated
</PropertyGroup>

<PropertyGroup Condition="'$(DisableNullableWarnings)' == 'true'">
<NoWarn>$(NoWarn);8600;8601;8602;8603;8604;8605;8610;8616;8617;8714</NoWarn>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If/when the compiler adds another one, will we remember to update this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather maintain a simple warning set than modify every file and project in our repo

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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'" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to fight with your other property in the Imports.targets?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not moving VB along as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VB is blocked until this issue is fixed dotnet/sdk#10591

Comment thread src/Compilers/CSharp/Portable/Microsoft.CodeAnalysis.CSharp.csproj Outdated
@nguerrera
Copy link
Copy Markdown
Contributor

@nguerrera

@jaredpar
Copy link
Copy Markdown
Member Author

jaredpar commented Feb 5, 2020

@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 Index being available in our netcoreapp3.1 targets.

-->
<UserRuntimeConfig Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(OutputType)' == 'Exe'">$(RepositoryEngineeringDir)config\runtimeconfig.template.json</UserRuntimeConfig>

<DisableNullableWarnings Condition="'$(DisableNullableWarnings)' == '' AND '$(TargetFramework)' != '' AND '$(TargetFramework)' != 'netcoreapp3.1'">true</DisableNullableWarnings>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given how many people that confused, perhaps this is worth a comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Comment thread eng/targets/Imports.targets Outdated
<!-- 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>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated whitespace change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 6) with a couple small suggestions.

@jaredpar
Copy link
Copy Markdown
Member Author

jaredpar commented Feb 6, 2020

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.

@jaredpar jaredpar merged commit aaed113 into dotnet:master Feb 6, 2020
@jaredpar jaredpar deleted the mt branch February 6, 2020 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants