Skip to content

Reference older MSBuild for .NET Framework tasks#26080

Merged
joeloff merged 1 commit intodotnet:release/6.0.4xxfrom
rainersigwald:reference-older-msbuild
Jun 21, 2022
Merged

Reference older MSBuild for .NET Framework tasks#26080
joeloff merged 1 commit intodotnet:release/6.0.4xxfrom
rainersigwald:reference-older-msbuild

Conversation

@rainersigwald
Copy link
Copy Markdown
Member

Updates of MSBuild's transitive references have caused insertion breaks twice now, in #25507 and #25897. Both happened because, in older-but-still-supported Visual Studio environments, MSBuild's binding redirects mismatched what the task's compilation environment provided, causing some types to be resolved from an older version of an assembly and some types to be resolved from a newer, creating mismatches at runtime.

I initially "fixed" this by manually downgrading some of the transitive references at SDK compilation time in 66826cc. But that is confusing, labor-intensive, and hard to maintain.

This is a different solution: explicitly target the version of MSBuild that the tasks are expected to run on. MSBuild's compatibility guarantees are such that tasks compiled for an older MSBuild should always work, so this should be safe, and it more accurately reflects the intent of the SDK tasks: they should work on older MSBuild (and thus Visual Studio).

@ghost
Copy link
Copy Markdown

ghost commented Jun 17, 2022

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@joeloff
Copy link
Copy Markdown
Member

joeloff commented Jun 20, 2022

Do we need more changes? I'm seeing different missing method exceptions now in the Helix logs

C:\h\w\C36F0AA6\p\d\sdk\6.0.400-ci\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(628,5): error MSB4018: System.MissingMethodException: Method not found: 'System.Collections.Immutable.ImmutableArray`1<System.Reflection.Metadata.CustomAttributeTypedArgument`1<!0>> System.Reflection.Metadata.CustomAttributeValue`1.get_FixedArguments()

This fixes a class of break in the scenario "New .NET SDK running on old
Visual Studio/ MSBuild.exe" by ensuring that the SDK task assemblies
don't get references to newer versions of MSBuild's transitive
references than are available in the current MSBuild environment, even
if that's older.

We have to specify explicit old versions of some `System.*` assemblies
to get versions that will be consistent with the older versions of
MSBuild.
@rainersigwald rainersigwald force-pushed the reference-older-msbuild branch from da868fd to cbc6080 Compare June 20, 2022 16:03
@rainersigwald
Copy link
Copy Markdown
Member Author

@joeloff sorry, latest push should be a bit better!

@joeloff
Copy link
Copy Markdown
Member

joeloff commented Jun 20, 2022

@dtivel Any idea why the PEM tests are failing on Linux. Has anything changed you're aware of? It's finding the file, just not the certificate, but finding the certificate on Windows.

@dtivel
Copy link
Copy Markdown
Contributor

dtivel commented Jun 20, 2022

@joeloff, I'm not aware of any changes. How can I debug this failure?

@joeloff
Copy link
Copy Markdown
Member

joeloff commented Jun 20, 2022

@joeloff, I'm not aware of any changes. How can I debug this failure?

WSL is the only option I know of, so I'm going to try and repro this.

I tried the following:

using System.Security.Cryptography.X509Certificates;

X509Certificate2Collection _certificates = new();

_certificates.ImportFromPemFile("/mnt/c/git/forks/sdk/src/Layout/redist/trustedroots/codesignctl.pem");
var results = _certificates.Find(X509FindType.FindByThumbprint, "0563b8630d62d75abbc8ab1e4bdfb5a899b24d43", validOnly: true);

foreach (var r in results)
{
    Console.WriteLine($"{r.SubjectName.Name}");
}

and it finds the certificate and prints the information

image

@rainersigwald
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@joeloff joeloff merged commit e6bffb3 into dotnet:release/6.0.4xx Jun 21, 2022
@rainersigwald rainersigwald deleted the reference-older-msbuild branch June 21, 2022 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants