From 1d36c06e67e8812542d03aecdb8627b780fcd6cc Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 31 Mar 2025 14:52:27 +0200 Subject: [PATCH 01/15] Use Roslyn from SDK always for SDK-based project builds --- Directory.Packages.props | 2 + sdk.sln | 2 + .../Microsoft.NET.Sdk.BeforeCommon.targets | 18 +++ .../Microsoft.NET.Build.Tests.csproj | 3 + .../RoslynBuildTaskTests.cs | 128 ++++++++++++++++++ .../Commands/DotnetBuildCommand.cs | 21 +++ .../Commands/MSBuildCommand.cs | 8 ++ 7 files changed, 182 insertions(+) create mode 100644 test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 8ffd76b881a4..85b1ed9ccb97 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,6 +6,7 @@ + @@ -75,6 +76,7 @@ + diff --git a/sdk.sln b/sdk.sln index dcbce4f1cfec..2bf8d496bd7d 100644 --- a/sdk.sln +++ b/sdk.sln @@ -19,7 +19,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build.sh = build.sh Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets + Directory.Packages.props = Directory.Packages.props LICENSE.TXT = LICENSE.TXT + NuGet.config = NuGet.config README.md = README.md restore.cmd = restore.cmd restore.sh = restore.sh diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index 51c3f9b12aec..57095772a8a8 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -299,4 +299,22 @@ Copyright (c) .NET Foundation. All rights reserved. true + + + true + + + $(MSBuildThisFileDirectory)..\..\..\Roslyn + $(MSBuildThisFileDirectory)..\..\..\Roslyn\binfx + ..\bincore + $(MSBuildThisFileDirectory)..\..\..\Roslyn\Microsoft.CSharp.Core.targets + $(MSBuildThisFileDirectory)..\..\..\Roslyn\Microsoft.VisualBasic.Core.targets + + diff --git a/test/Microsoft.NET.Build.Tests/Microsoft.NET.Build.Tests.csproj b/test/Microsoft.NET.Build.Tests/Microsoft.NET.Build.Tests.csproj index dcc4e655313c..d3f95c43ab2c 100644 --- a/test/Microsoft.NET.Build.Tests/Microsoft.NET.Build.Tests.csproj +++ b/test/Microsoft.NET.Build.Tests/Microsoft.NET.Build.Tests.csproj @@ -21,14 +21,17 @@ + + + diff --git a/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs b/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs new file mode 100644 index 000000000000..bcc30186ddbb --- /dev/null +++ b/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs @@ -0,0 +1,128 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.CompilerServices; +using Basic.CompilerLog.Util; +using Microsoft.Build.Logging.StructuredLogger; + +namespace Microsoft.NET.Build.Tests; + +public sealed class RoslynBuildTaskTests(ITestOutputHelper log) : SdkTest(log) +{ + private const string CoreCompilerFileName = "csc.dll"; + private const string FxCompilerFileName = "csc.exe"; + + [FullMSBuildOnlyTheory, CombinatorialData] + public void FullMSBuild_SdkStyle(bool useSharedCompilation) + { + var testAsset = CreateProject(useSharedCompilation); + var buildCommand = BuildAndRunUsingMSBuild(testAsset); + VerifyCompiler(buildCommand, CoreCompilerFileName, useSharedCompilation); + } + + [FullMSBuildOnlyTheory, CombinatorialData] + public void FullMSBuild_SdkStyle_OptOut(bool useSharedCompilation) + { + var testAsset = CreateProject(useSharedCompilation).WithProjectChanges(static doc => + { + doc.Root!.Element("PropertyGroup")!.Add(new XElement("RoslynUseSdkCompiler", "false")); + }); + var buildCommand = BuildAndRunUsingMSBuild(testAsset); + VerifyCompiler(buildCommand, FxCompilerFileName, useSharedCompilation); + } + + [FullMSBuildOnlyTheory, CombinatorialData] + public void FullMSBuild_NonSdkStyle(bool useSharedCompilation) + { + var testAsset = CreateProject(useSharedCompilation, static project => + { + project.IsSdkProject = false; + project.TargetFrameworkVersion = "v4.7.2"; + }); + var buildCommand = BuildAndRunUsingMSBuild(testAsset); + VerifyCompiler(buildCommand, FxCompilerFileName, useSharedCompilation); + } + + [Theory, CombinatorialData] + public void DotNet(bool useSharedCompilation) + { + var testAsset = CreateProject(useSharedCompilation); + var buildCommand = BuildAndRunUsingDotNet(testAsset); + VerifyCompiler(buildCommand, CoreCompilerFileName, useSharedCompilation); + } + + private TestAsset CreateProject(bool useSharedCompilation, Action? configure = null, [CallerMemberName] string callingMethod = "") + { + var project = new TestProject + { + Name = "App1", + IsExe = true, + SourceFiles = + { + ["Program.cs"] = """ + class Program + { + static void Main() + { + System.Console.WriteLine(40 + 2); + } + } + """, + }, + }; + + // UseSharedCompilation should be the default, so set it only if false. + if (!useSharedCompilation) + { + project.AdditionalProperties["UseSharedCompilation"] = "false"; + } + + configure?.Invoke(project); + return _testAssetsManager.CreateTestProject(project, callingMethod: callingMethod); + } + + private TestCommand BuildAndRunUsingMSBuild(TestAsset testAsset) + { + var buildCommand = new MSBuildCommand(testAsset, "Build"); + buildCommand.WithWorkingDirectory(testAsset.Path) + .Execute("-bl").Should().Pass(); + + Run(buildCommand.GetOutputFile()); + + return buildCommand; + } + + private TestCommand BuildAndRunUsingDotNet(TestAsset testAsset) + { + var buildCommand = new DotnetBuildCommand(testAsset); + buildCommand.Execute("-bl").Should().Pass(); + + Run(buildCommand.GetOutputFile()); + + return buildCommand; + } + + private void Run(FileInfo outputFile) + { + var runCommand = new RunExeCommand(Log, outputFile.FullName); + runCommand.Execute().Should().Pass() + .And.HaveStdOut("42"); + } + + private static void VerifyCompiler(TestCommand buildCommand, string compilerFileName, bool usedCompilerServer) + { + var binaryLogPath = Path.Join(buildCommand.WorkingDirectory, "msbuild.binlog"); + using (var reader = BinaryLogReader.Create(binaryLogPath)) + { + var call = reader.ReadAllCompilerCalls().Should().ContainSingle().Subject; + Path.GetFileName(call.CompilerFilePath).Should().Be(compilerFileName); + } + + // Verify compiler server message. + var compilerServerMesssages = BinaryLog.ReadBuild(binaryLogPath).FindChildrenRecursive( + static message => message.Text.StartsWith("CompilerServer:", StringComparison.Ordinal)); + compilerServerMesssages.Should().ContainSingle().Which.Text.Should().StartWith(usedCompilerServer + ? "CompilerServer: server - server processed compilation - " + : "CompilerServer: tool - using command line tool by design"); + } +} diff --git a/test/Microsoft.NET.TestFramework/Commands/DotnetBuildCommand.cs b/test/Microsoft.NET.TestFramework/Commands/DotnetBuildCommand.cs index 8c5cce77583d..f5639c18ebaf 100644 --- a/test/Microsoft.NET.TestFramework/Commands/DotnetBuildCommand.cs +++ b/test/Microsoft.NET.TestFramework/Commands/DotnetBuildCommand.cs @@ -1,10 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics; + namespace Microsoft.NET.TestFramework.Commands { public class DotnetBuildCommand : DotnetCommand { + public TestAsset? TestAsset { get; } + public DotnetBuildCommand(ITestOutputHelper log, params string[] args) : base(log) { Arguments.Add("build"); @@ -13,6 +17,8 @@ public DotnetBuildCommand(ITestOutputHelper log, params string[] args) : base(lo public DotnetBuildCommand(TestAsset testAsset, params string[] args) : this(testAsset.Log, args) { + TestAsset = testAsset; + if (testAsset.TestProject != null && testAsset.TestProject.Name is not null) { WorkingDirectory = Path.Combine(testAsset.TestRoot, testAsset.TestProject.Name); @@ -22,5 +28,20 @@ public DotnetBuildCommand(TestAsset testAsset, params string[] args) : this(test WorkingDirectory = testAsset.TestRoot; } } + + public DirectoryInfo GetOutputDirectory(string? targetFramework = null, string configuration = "Debug", string? runtimeIdentifier = null, string? platform = null) + { + Debug.Assert(TestAsset?.TestProject?.Name != null); + var projectPath = Path.Combine(TestAsset.Path, TestAsset.TestProject.Name); + return new DirectoryInfo(OutputPathCalculator.FromProject(projectPath, TestAsset) + .GetOutputDirectory(targetFramework, configuration, runtimeIdentifier, platform)); + } + + public FileInfo GetOutputFile() + { + Debug.Assert(TestAsset?.TestProject?.Name != null); + var extension = TestAsset.TestProject.IsExe ? ".exe" : ".dll"; + return GetOutputDirectory().File(TestAsset.TestProject.Name + extension); + } } } diff --git a/test/Microsoft.NET.TestFramework/Commands/MSBuildCommand.cs b/test/Microsoft.NET.TestFramework/Commands/MSBuildCommand.cs index 020ef737a5bc..9a34401e6185 100644 --- a/test/Microsoft.NET.TestFramework/Commands/MSBuildCommand.cs +++ b/test/Microsoft.NET.TestFramework/Commands/MSBuildCommand.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics; using Microsoft.DotNet.Cli.Utils; namespace Microsoft.NET.TestFramework.Commands @@ -84,6 +85,13 @@ public virtual DirectoryInfo GetOutputDirectory(string? targetFramework = null, return new DirectoryInfo(output); } + public FileInfo GetOutputFile() + { + Debug.Assert(TestAsset?.TestProject?.Name != null); + var extension = TestAsset.TestProject.IsExe ? ".exe" : ".dll"; + return GetOutputDirectory().File(TestAsset.TestProject.Name + extension); + } + public virtual DirectoryInfo GetIntermediateDirectory(string? targetFramework = null, string configuration = "Debug", string? runtimeIdentifier = null) { if (TestAsset != null) From 607133a772716e9a88d6733b1c2d07a8d67d8f83 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 31 Mar 2025 16:30:38 +0200 Subject: [PATCH 02/15] Use `.exe` suffix only on Windows --- test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs | 4 ++-- .../Commands/DotnetBuildCommand.cs | 7 ------- .../Commands/MSBuildCommand.cs | 8 -------- .../ProjectConstruction/TestProject.cs | 10 ++++++++++ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs b/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs index bcc30186ddbb..bc939bfcd97f 100644 --- a/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs +++ b/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs @@ -87,7 +87,7 @@ private TestCommand BuildAndRunUsingMSBuild(TestAsset testAsset) buildCommand.WithWorkingDirectory(testAsset.Path) .Execute("-bl").Should().Pass(); - Run(buildCommand.GetOutputFile()); + Run(buildCommand.GetOutputDirectory().File(testAsset.TestProject!.GetOutputFileName())); return buildCommand; } @@ -97,7 +97,7 @@ private TestCommand BuildAndRunUsingDotNet(TestAsset testAsset) var buildCommand = new DotnetBuildCommand(testAsset); buildCommand.Execute("-bl").Should().Pass(); - Run(buildCommand.GetOutputFile()); + Run(buildCommand.GetOutputDirectory().File(testAsset.TestProject!.GetOutputFileName())); return buildCommand; } diff --git a/test/Microsoft.NET.TestFramework/Commands/DotnetBuildCommand.cs b/test/Microsoft.NET.TestFramework/Commands/DotnetBuildCommand.cs index f5639c18ebaf..ad01fa1aed01 100644 --- a/test/Microsoft.NET.TestFramework/Commands/DotnetBuildCommand.cs +++ b/test/Microsoft.NET.TestFramework/Commands/DotnetBuildCommand.cs @@ -36,12 +36,5 @@ public DirectoryInfo GetOutputDirectory(string? targetFramework = null, string c return new DirectoryInfo(OutputPathCalculator.FromProject(projectPath, TestAsset) .GetOutputDirectory(targetFramework, configuration, runtimeIdentifier, platform)); } - - public FileInfo GetOutputFile() - { - Debug.Assert(TestAsset?.TestProject?.Name != null); - var extension = TestAsset.TestProject.IsExe ? ".exe" : ".dll"; - return GetOutputDirectory().File(TestAsset.TestProject.Name + extension); - } } } diff --git a/test/Microsoft.NET.TestFramework/Commands/MSBuildCommand.cs b/test/Microsoft.NET.TestFramework/Commands/MSBuildCommand.cs index 9a34401e6185..020ef737a5bc 100644 --- a/test/Microsoft.NET.TestFramework/Commands/MSBuildCommand.cs +++ b/test/Microsoft.NET.TestFramework/Commands/MSBuildCommand.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Diagnostics; using Microsoft.DotNet.Cli.Utils; namespace Microsoft.NET.TestFramework.Commands @@ -85,13 +84,6 @@ public virtual DirectoryInfo GetOutputDirectory(string? targetFramework = null, return new DirectoryInfo(output); } - public FileInfo GetOutputFile() - { - Debug.Assert(TestAsset?.TestProject?.Name != null); - var extension = TestAsset.TestProject.IsExe ? ".exe" : ".dll"; - return GetOutputDirectory().File(TestAsset.TestProject.Name + extension); - } - public virtual DirectoryInfo GetIntermediateDirectory(string? targetFramework = null, string configuration = "Debug", string? runtimeIdentifier = null) { if (TestAsset != null) diff --git a/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs b/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs index 0c329ae25b30..8e8939ee5afb 100644 --- a/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs +++ b/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics; using System.Runtime.CompilerServices; using Microsoft.Build.Utilities; using NuGet.Frameworks; @@ -533,5 +534,14 @@ public string GetOutputDirectory(string testRoot, string? targetFramework = null return GetOutputPathCalculator(testRoot) .GetOutputDirectory(targetFramework, configuration, runtimeIdentifier); } + + public string GetOutputFileName() + { + Debug.Assert(Name != null); + var extension = IsExe + ? (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty) + : ".dll"; + return Name + extension; + } } } From 17077253dd59230c0a22a3d9569cfaf945c2b60a Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Tue, 1 Apr 2025 17:52:45 +0200 Subject: [PATCH 03/15] Use testing Roslyn build --- NuGet.config | 2 ++ eng/Version.Details.xml | 40 ++++++++++++++++++++-------------------- eng/Versions.props | 18 +++++++++--------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/NuGet.config b/NuGet.config index 09870da28882..6b864f946160 100644 --- a/NuGet.config +++ b/NuGet.config @@ -32,6 +32,8 @@ + + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index d984233dfa27..6000ee9a560f 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -125,47 +125,47 @@ 345742da75dc6c5fe485ef1236d3f034ebcdcb53 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 - + https://github.com/dotnet/roslyn - 1def752c5d33903795069ccddb78599ba6da39d3 + f4c8c459d8dc8d779913d9711aa125c10f4e41b6 https://github.com/nuget/nuget.client diff --git a/eng/Versions.props b/eng/Versions.props index 91af0d88ad38..b339309daa93 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -222,15 +222,15 @@ - 4.14.0-3.25171.27 - 4.14.0-3.25171.27 - 4.14.0-3.25171.27 - 4.14.0-3.25171.27 - 4.14.0-3.25171.27 - 4.14.0-3.25171.27 - 4.14.0-3.25171.27 - 4.14.0-3.25171.27 - 4.14.0-3.25171.27 + 4.14.0-3.25201.12 + 4.14.0-3.25201.12 + 4.14.0-3.25201.12 + 4.14.0-3.25201.12 + 4.14.0-3.25201.12 + 4.14.0-3.25201.12 + 4.14.0-3.25201.12 + 4.14.0-3.25201.12 + 4.14.0-3.25201.12 From 7e52b1b5d6a7437b22ba490f02c0cd52c93f9d30 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Wed, 2 Apr 2025 16:12:52 +0200 Subject: [PATCH 04/15] Avoid automatic toolset download when using core compiler --- .../targets/Microsoft.NET.Sdk.Common.targets | 1 + .../GivenThatWeWantToUseFrameworkRoslyn.cs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets index 5e357b79cad1..83d82b1710a5 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets @@ -62,6 +62,7 @@ Copyright (c) .NET Foundation. All rights reserved. This is to reduce 'tearing'/dependency mismatch, but as always users can override this behavior by disabling the hosted compiler flag. This is done in Common.targets so that it applies to ApiCompat which uses RoslynTargetsPath in the outer build. --> true diff --git a/test/Microsoft.NET.Restore.Tests/GivenThatWeWantToUseFrameworkRoslyn.cs b/test/Microsoft.NET.Restore.Tests/GivenThatWeWantToUseFrameworkRoslyn.cs index 0aaf506b7854..92bf06b432d0 100644 --- a/test/Microsoft.NET.Restore.Tests/GivenThatWeWantToUseFrameworkRoslyn.cs +++ b/test/Microsoft.NET.Restore.Tests/GivenThatWeWantToUseFrameworkRoslyn.cs @@ -58,6 +58,7 @@ public void It_downloads_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_ // simulate mismatched MSBuild versions project.AdditionalProperties.Add("_IsDisjointMSBuildVersion", "true"); + project.AdditionalProperties.Add("RoslynUseSdkCompiler", "false"); var testAsset = _testAssetsManager .CreateTestProject(project); @@ -143,6 +144,7 @@ public void It_throws_a_warning_when_NuGetPackageRoot_is_empty() // simulate mismatched MSBuild versions project.AdditionalProperties.Add("_IsDisjointMSBuildVersion", "true"); + project.AdditionalProperties.Add("RoslynUseSdkCompiler", "false"); var testAsset = _testAssetsManager .CreateTestProject(project); @@ -178,7 +180,7 @@ public void It_does_not_throw_a_warning_when_NuGetPackageRoot_is_empty_in_wpftmp }; // simulate mismatched MSBuild versions via _IsDisjointMSBuildVersion - buildCommand.Execute("-p:_IsDisjointMSBuildVersion=true") + buildCommand.Execute("-p:_IsDisjointMSBuildVersion=true -p:RoslynUseSdkCompiler=false") .Should().Pass().And.NotHaveStdOutContaining("NETSDK1221"); Assert.True(File.Exists(Path.Combine(testAsset.Path, "obj", "net472", "MainWindow.g.cs"))); From a73f785ef66b0d7af6a76cd01a52585901696a7f Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Thu, 3 Apr 2025 13:18:31 +0200 Subject: [PATCH 05/15] Use absolute path for RoslynToolsDirectory --- .../targets/Microsoft.NET.Sdk.BeforeCommon.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index 57095772a8a8..ddf76b71a95c 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -312,7 +312,7 @@ Copyright (c) .NET Foundation. All rights reserved. $(MSBuildThisFileDirectory)..\..\..\Roslyn $(MSBuildThisFileDirectory)..\..\..\Roslyn\binfx - ..\bincore + $(MSBuildThisFileDirectory)..\..\..\Roslyn\bincore $(MSBuildThisFileDirectory)..\..\..\Roslyn\Microsoft.CSharp.Core.targets $(MSBuildThisFileDirectory)..\..\..\Roslyn\Microsoft.VisualBasic.Core.targets From 731050c5a3573561a2db95613120efe8d54ba223 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Tue, 8 Apr 2025 10:01:02 +0200 Subject: [PATCH 06/15] Update Roslyn version --- eng/Version.Details.xml | 40 ++++++++++++++++++++-------------------- eng/Versions.props | 18 +++++++++--------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 0bb4fb21c328..317a1e94f3e8 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -125,47 +125,47 @@ e165bbea9e27ceb4c8b91c22bd0c564ff1dc8b25 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 - + https://github.com/dotnet/roslyn - f4c8c459d8dc8d779913d9711aa125c10f4e41b6 + edc0f9d010751b2ea3cfa576048ae7dde3a5f251 https://github.com/nuget/nuget.client diff --git a/eng/Versions.props b/eng/Versions.props index 6c77a2b448e2..86bdcd1849a2 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -222,15 +222,15 @@ - 4.14.0-3.25201.12 - 4.14.0-3.25201.12 - 4.14.0-3.25201.12 - 4.14.0-3.25201.12 - 4.14.0-3.25201.12 - 4.14.0-3.25201.12 - 4.14.0-3.25201.12 - 4.14.0-3.25201.12 - 4.14.0-3.25201.12 + 4.14.0-3.25207.3 + 4.14.0-3.25207.3 + 4.14.0-3.25207.3 + 4.14.0-3.25207.3 + 4.14.0-3.25207.3 + 4.14.0-3.25207.3 + 4.14.0-3.25207.3 + 4.14.0-3.25207.3 + 4.14.0-3.25207.3 From 1d401ec475010fa71e528b2bc1ab45e7f32eae5a Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Wed, 9 Apr 2025 11:22:06 +0200 Subject: [PATCH 07/15] Exclude binfx from Crossgen --- src/Layout/redist/targets/Crossgen.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Layout/redist/targets/Crossgen.targets b/src/Layout/redist/targets/Crossgen.targets index ffd8a2045c7d..468dced5ee32 100644 --- a/src/Layout/redist/targets/Crossgen.targets +++ b/src/Layout/redist/targets/Crossgen.targets @@ -54,7 +54,7 @@ - + From 577d565d58134f0b81b42d02dd8d928f99dcf7be Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Wed, 9 Apr 2025 16:19:28 +0200 Subject: [PATCH 08/15] Fix Razor targets --- src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Compilation.targets | 1 + src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Component.targets | 1 + .../Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets | 1 + 3 files changed, 3 insertions(+) diff --git a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Compilation.targets b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Compilation.targets index 3bd2e53fe1eb..2939c13a94c2 100644 --- a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Compilation.targets +++ b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Compilation.targets @@ -175,6 +175,7 @@ Copyright (c) .NET Foundation. All rights reserved. TargetType="Library" ToolExe="$(CscToolExe)" ToolPath="$(CscToolPath)" + ToolsDirectory="$(RoslynToolsDirectory)" TreatWarningsAsErrors="$(TreatWarningsAsErrors)" UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)" UseSharedCompilation="$(UseSharedCompilation)" diff --git a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Component.targets b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Component.targets index f7d59437130e..8a62afd489ac 100644 --- a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Component.targets +++ b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Component.targets @@ -240,6 +240,7 @@ Copyright (c) .NET Foundation. All rights reserved. TargetType="$(OutputType)" ToolExe="$(CscToolExe)" ToolPath="$(CscToolPath)" + ToolsDirectory="$(RoslynToolsDirectory)" TreatWarningsAsErrors="$(TreatWarningsAsErrors)" UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)" UseSharedCompilation="$(UseSharedCompilation)" diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index 8688eee3481f..0695805bfaa1 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -1244,6 +1244,7 @@ Copyright (c) .NET Foundation. All rights reserved. TargetType="Library" ToolExe="$(CscToolExe)" ToolPath="$(CscToolPath)" + ToolsDirectory="$(RoslynToolsDirectory)" UseSharedCompilation="$(UseSharedCompilation)"> From ab396fbf6d84b1a2aa6d0a2a466d16f2e421d7a5 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Thu, 10 Apr 2025 15:50:54 +0200 Subject: [PATCH 09/15] Replace RoslynToolsDirectory with RoslynCompilerType --- .../general/decouple-vs-and-net-sdk.md | 4 +- documentation/general/torn-sdk.md | 3 ++ ...icrosoft.NET.Sdk.Razor.Compilation.targets | 2 +- .../Microsoft.NET.Sdk.Razor.Component.targets | 2 +- .../Microsoft.NET.Sdk.BeforeCommon.targets | 45 +++++++++++++++---- .../targets/Microsoft.NET.Sdk.Common.targets | 17 ------- .../targets/Microsoft.NET.Sdk.targets | 2 +- .../RoslynBuildTaskTests.cs | 2 +- 8 files changed, 46 insertions(+), 31 deletions(-) diff --git a/documentation/general/decouple-vs-and-net-sdk.md b/documentation/general/decouple-vs-and-net-sdk.md index 84d6e739c9dd..aa483c3afc7d 100644 --- a/documentation/general/decouple-vs-and-net-sdk.md +++ b/documentation/general/decouple-vs-and-net-sdk.md @@ -117,13 +117,13 @@ There is nothing preventing NuGet based analyzers from following the same model Solutions that mix .NET SDK and Visual Studio projects will end up with multiple compiler servers running. This is a result of the .NET SDK projects using the compiler from the .NET SDK and non-SDK projects using the compiler from Visual Studio. There is nothing functionally wrong with this but it's possible customers will notice this and ask questions about it. -The compiler will offer a property that allows SDK projects to use the MSBuild version of the compiler when being built with `msbuild`: `true`. This can be added to a `Directory.Build.props` file to impact the entire solution. This is not expected to be a common scenario but is available for customers who need it. This property will be ignored when using `dotnet build` as there is no way to fall back to the Visual Studio compiler in that scenario. +The compiler will offer a property that allows SDK projects to use the MSBuild version of the compiler when being built with `msbuild`: `Framework`. This can be added to a `Directory.Build.props` file to impact the entire solution. This is not expected to be a common scenario but is available for customers who need it. This property will be ignored when using `dotnet build` as there is no way to fall back to the Visual Studio compiler in that scenario. ### .NET Framework based analyzers There are a few analyzers which are built against .NET Framework TFMs. That means when loaded in a .NET Core compiler it could lead to compatibility issues. This is not expected to be a significant issue as our processes have been pushing customers to target `netstandard` in analyzers for 5+ years. However it is possible that some customers will run into issues here. -For those customers we will recommend that they set `true` in their build to ensure a .NET Framework based compiler is used. However, it is not our intent to support loading .NET Framework based analyzers in perpetuity. Starting in .NET 12 the compiler will begin issueing warnings is this setup when it detects framework analyzers, and this will become an error in .NET 13. Non-SDK projects will support loading framework based analyzers for the foreseeable future. +For those customers we will recommend that they set `Framework` in their build to ensure a .NET Framework based compiler is used. However, it is not our intent to support loading .NET Framework based analyzers in perpetuity. Starting in .NET 12 the compiler will begin issueing warnings is this setup when it detects framework analyzers, and this will become an error in .NET 13. Non-SDK projects will support loading framework based analyzers for the foreseeable future. ### Build server shutdown diff --git a/documentation/general/torn-sdk.md b/documentation/general/torn-sdk.md index e8de8b9f945d..53f83199ef0e 100644 --- a/documentation/general/torn-sdk.md +++ b/documentation/general/torn-sdk.md @@ -1,5 +1,8 @@ # Torn .NET SDK +> [!CAUTION] +> This document has been superseded by [Decoupling the .NET SDK and Visual Studio](decouple-vs-and-net-sdk.md). + ## Terminology - **msbuild**: refers the .NET Framework based msbuild included with Visual Studio. diff --git a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Compilation.targets b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Compilation.targets index 2939c13a94c2..0b008ea415bd 100644 --- a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Compilation.targets +++ b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Compilation.targets @@ -129,6 +129,7 @@ Copyright (c) .NET Foundation. All rights reserved. ChecksumAlgorithm="$(ChecksumAlgorithm)" CodeAnalysisRuleSet="$(ResolvedCodeAnalysisRuleSet)" CodePage="$(CodePage)" + CompilerType="$(RoslynCompilerType)" DebugType="$(DebugType)" DefineConstants="$(DefineConstants)" DelaySign="$(DelaySign)" @@ -175,7 +176,6 @@ Copyright (c) .NET Foundation. All rights reserved. TargetType="Library" ToolExe="$(CscToolExe)" ToolPath="$(CscToolPath)" - ToolsDirectory="$(RoslynToolsDirectory)" TreatWarningsAsErrors="$(TreatWarningsAsErrors)" UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)" UseSharedCompilation="$(UseSharedCompilation)" diff --git a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Component.targets b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Component.targets index 8a62afd489ac..e5fc1a9a2ce3 100644 --- a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Component.targets +++ b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Component.targets @@ -195,6 +195,7 @@ Copyright (c) .NET Foundation. All rights reserved. ChecksumAlgorithm="$(ChecksumAlgorithm)" CodeAnalysisRuleSet="$(ResolvedCodeAnalysisRuleSet)" CodePage="$(CodePage)" + CompilerType="$(RoslynCompilerType)" DebugType="$(DebugType)" DefineConstants="$(DefineConstants)" DelaySign="$(DelaySign)" @@ -240,7 +241,6 @@ Copyright (c) .NET Foundation. All rights reserved. TargetType="$(OutputType)" ToolExe="$(CscToolExe)" ToolPath="$(CscToolPath)" - ToolsDirectory="$(RoslynToolsDirectory)" TreatWarningsAsErrors="$(TreatWarningsAsErrors)" UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)" UseSharedCompilation="$(UseSharedCompilation)" diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index ddf76b71a95c..9fef2540714d 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -303,18 +303,47 @@ Copyright (c) .NET Foundation. All rights reserved. Use Roslyn deployed with SDK for builds of SDK-style projects (regardless of whether the initiator is `dotnet` or `msbuild`). See https://github.com/dotnet/sdk/blob/main/documentation/general/decouple-vs-and-net-sdk.md. --> - - true - - + + + + + + + FrameworkPackage + + + + + Core + + + + + FrameworkPackage + + + + + Framework + + + + $(MSBuildThisFileDirectory)..\..\..\Roslyn $(MSBuildThisFileDirectory)..\..\..\Roslyn\binfx - $(MSBuildThisFileDirectory)..\..\..\Roslyn\bincore $(MSBuildThisFileDirectory)..\..\..\Roslyn\Microsoft.CSharp.Core.targets $(MSBuildThisFileDirectory)..\..\..\Roslyn\Microsoft.VisualBasic.Core.targets + + $(NuGetPackageRoot)\microsoft.net.sdk.compilers.toolset\$(NETCoreSdkVersion) + <_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage>true + <_MicrosoftNetSdkCompilersToolsetPackageRootEmpty Condition="'$(NuGetPackageRoot)' == ''">true + + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets index 9e44078e7c7a..2d650a4101a6 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets @@ -75,21 +75,4 @@ Copyright (c) .NET Foundation. All rights reserved. - - - true - - - - $(NuGetPackageRoot)\microsoft.net.sdk.compilers.toolset\$(NETCoreSdkVersion) - <_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage>true - <_MicrosoftNetSdkCompilersToolsetPackageRootEmpty Condition="'$(NuGetPackageRoot)' == ''">true - - diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index 0695805bfaa1..464dd8659a7c 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -1235,6 +1235,7 @@ Copyright (c) .NET Foundation. All rights reserved. PublicSign="$(PublicSign)" PathMap="$(PathMap)" Features="$(Features)" + CompilerType="$(RoslynCompilerType)" DelaySign="$(DelaySign)" Deterministic="$(Deterministic)" DisabledWarnings="$(DisabledWarnings)" @@ -1244,7 +1245,6 @@ Copyright (c) .NET Foundation. All rights reserved. TargetType="Library" ToolExe="$(CscToolExe)" ToolPath="$(CscToolPath)" - ToolsDirectory="$(RoslynToolsDirectory)" UseSharedCompilation="$(UseSharedCompilation)"> diff --git a/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs b/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs index bc939bfcd97f..5cb8703ef2df 100644 --- a/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs +++ b/test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs @@ -25,7 +25,7 @@ public void FullMSBuild_SdkStyle_OptOut(bool useSharedCompilation) { var testAsset = CreateProject(useSharedCompilation).WithProjectChanges(static doc => { - doc.Root!.Element("PropertyGroup")!.Add(new XElement("RoslynUseSdkCompiler", "false")); + doc.Root!.Element("PropertyGroup")!.Add(new XElement("RoslynCompilerType", "Framework")); }); var buildCommand = BuildAndRunUsingMSBuild(testAsset); VerifyCompiler(buildCommand, FxCompilerFileName, useSharedCompilation); From c91bbd48422656ebf0b4368c2872d5b044a71bf8 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Thu, 10 Apr 2025 21:03:10 +0200 Subject: [PATCH 10/15] Update Roslyn --- eng/Version.Details.xml | 40 ++++++++++++++++++++-------------------- eng/Versions.props | 18 +++++++++--------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 9a00b6164914..572c00f068de 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -125,47 +125,47 @@ 4ba36db1f42f33a66d9677f0b9d589d39b204a9c - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 - + https://github.com/dotnet/roslyn - edc0f9d010751b2ea3cfa576048ae7dde3a5f251 + c7525777ea55920c841e57cb084a76c2e05838d7 https://github.com/nuget/nuget.client diff --git a/eng/Versions.props b/eng/Versions.props index 892688ce1128..2b86fc17b6fb 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -222,15 +222,15 @@ - 4.14.0-3.25207.3 - 4.14.0-3.25207.3 - 4.14.0-3.25207.3 - 4.14.0-3.25207.3 - 4.14.0-3.25207.3 - 4.14.0-3.25207.3 - 4.14.0-3.25207.3 - 4.14.0-3.25207.3 - 4.14.0-3.25207.3 + 4.14.0-3.25210.1 + 4.14.0-3.25210.1 + 4.14.0-3.25210.1 + 4.14.0-3.25210.1 + 4.14.0-3.25210.1 + 4.14.0-3.25210.1 + 4.14.0-3.25210.1 + 4.14.0-3.25210.1 + 4.14.0-3.25210.1 From f3732fd24fdea1f828683e7ffe14d4003cd282e5 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 11 Apr 2025 13:42:01 +0200 Subject: [PATCH 11/15] Fix automatic toolset package opt in --- .../Microsoft.NET.Sdk.BeforeCommon.targets | 10 ++-------- .../targets/Microsoft.NET.Sdk.Common.targets | 6 ++++++ .../GivenThatWeWantToUseFrameworkRoslyn.cs | 17 +++++++++++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index 9fef2540714d..6f90f3514f0b 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -322,8 +322,8 @@ Copyright (c) .NET Foundation. All rights reserved. + and ('$(MSBuildProjectExtension)' == '.csproj' + or '$(MSBuildProjectExtension)' == '.vbproj')"> FrameworkPackage @@ -340,10 +340,4 @@ Copyright (c) .NET Foundation. All rights reserved. $(MSBuildThisFileDirectory)..\..\..\Roslyn\Microsoft.VisualBasic.Core.targets - - $(NuGetPackageRoot)\microsoft.net.sdk.compilers.toolset\$(NETCoreSdkVersion) - <_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage>true - <_MicrosoftNetSdkCompilersToolsetPackageRootEmpty Condition="'$(NuGetPackageRoot)' == ''">true - - diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets index 2d650a4101a6..17f49502be28 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Common.targets @@ -75,4 +75,10 @@ Copyright (c) .NET Foundation. All rights reserved. + + $(NuGetPackageRoot)\microsoft.net.sdk.compilers.toolset\$(NETCoreSdkVersion) + <_NeedToDownloadMicrosoftNetSdkCompilersToolsetPackage>true + <_MicrosoftNetSdkCompilersToolsetPackageRootEmpty Condition="'$(NuGetPackageRoot)' == ''">true + + diff --git a/test/Microsoft.NET.Restore.Tests/GivenThatWeWantToUseFrameworkRoslyn.cs b/test/Microsoft.NET.Restore.Tests/GivenThatWeWantToUseFrameworkRoslyn.cs index 92bf06b432d0..e5bd7e1fec70 100644 --- a/test/Microsoft.NET.Restore.Tests/GivenThatWeWantToUseFrameworkRoslyn.cs +++ b/test/Microsoft.NET.Restore.Tests/GivenThatWeWantToUseFrameworkRoslyn.cs @@ -58,7 +58,9 @@ public void It_downloads_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_ // simulate mismatched MSBuild versions project.AdditionalProperties.Add("_IsDisjointMSBuildVersion", "true"); - project.AdditionalProperties.Add("RoslynUseSdkCompiler", "false"); + + // avoid opt in to RoslynCompilerType=Core + string[] args = ["-p:DOTNET_HOST_PATH=", "-p:DOTNET_EXPERIMENTAL_HOST_PATH="]; var testAsset = _testAssetsManager .CreateTestProject(project); @@ -69,7 +71,7 @@ public void It_downloads_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_ testAsset.GetRestoreCommand(Log, relativePath: testProjectName) .WithEnvironmentVariable("NUGET_PACKAGES", customPackagesDir) - .Execute().Should().Pass(); + .Execute(args).Should().Pass(); var toolsetPackageDir = Path.Combine(customPackagesDir, "microsoft.net.sdk.compilers.toolset"); @@ -79,7 +81,7 @@ public void It_downloads_Microsoft_Net_Compilers_Toolset_Framework_when_MSBuild_ new BuildCommand(testAsset) .WithEnvironmentVariable("NUGET_PACKAGES", customPackagesDir) - .Execute().Should().Pass().And + .Execute(args).Should().Pass().And .HaveStdOutContaining(Path.Combine(toolsetPackageDir, toolsetPackageVersion, "csc.exe") + " /noconfig"); } @@ -144,7 +146,9 @@ public void It_throws_a_warning_when_NuGetPackageRoot_is_empty() // simulate mismatched MSBuild versions project.AdditionalProperties.Add("_IsDisjointMSBuildVersion", "true"); - project.AdditionalProperties.Add("RoslynUseSdkCompiler", "false"); + + // avoid opt in to RoslynCompilerType=Core + string[] args = ["-p:DOTNET_HOST_PATH=", "-p:DOTNET_EXPERIMENTAL_HOST_PATH="]; var testAsset = _testAssetsManager .CreateTestProject(project); @@ -155,7 +159,7 @@ public void It_throws_a_warning_when_NuGetPackageRoot_is_empty() var command = (MSBuildCommand)new MSBuildCommand(testAsset, "Restore;Build") .WithEnvironmentVariable("NUGET_PACKAGES", customPackagesDir); - command.ExecuteWithoutRestore() + command.ExecuteWithoutRestore(args) .Should().Pass().And.HaveStdOutContaining("NETSDK1221"); // The package is downloaded, but the targets cannot find the path to it @@ -180,7 +184,8 @@ public void It_does_not_throw_a_warning_when_NuGetPackageRoot_is_empty_in_wpftmp }; // simulate mismatched MSBuild versions via _IsDisjointMSBuildVersion - buildCommand.Execute("-p:_IsDisjointMSBuildVersion=true -p:RoslynUseSdkCompiler=false") + // avoid opt in to RoslynCompilerType=Core by unsetting DOTNET_HOST_PATH and DOTNET_EXPERIMENTAL_HOST_PATH + buildCommand.Execute("-p:_IsDisjointMSBuildVersion=true", "-p:DOTNET_HOST_PATH=", "-p:DOTNET_EXPERIMENTAL_HOST_PATH=") .Should().Pass().And.NotHaveStdOutContaining("NETSDK1221"); Assert.True(File.Exists(Path.Combine(testAsset.Path, "obj", "net472", "MainWindow.g.cs"))); From 7a0a90f2d49d1d4a65eb91c929cbc468f71c9e2e Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 11 Apr 2025 13:48:08 +0200 Subject: [PATCH 12/15] Exclude binfx from linux publishing --- src/Layout/redist/targets/GenerateLayout.targets | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Layout/redist/targets/GenerateLayout.targets b/src/Layout/redist/targets/GenerateLayout.targets index 4e85b6f2fd60..7938cfcd2869 100644 --- a/src/Layout/redist/targets/GenerateLayout.targets +++ b/src/Layout/redist/targets/GenerateLayout.targets @@ -50,6 +50,8 @@ + + From 54b58814e246e2a8d4350af34fef3224b8a06331 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 14 Apr 2025 11:58:49 +0200 Subject: [PATCH 13/15] Document RoslynCompilerType --- documentation/general/decouple-vs-and-net-sdk.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/documentation/general/decouple-vs-and-net-sdk.md b/documentation/general/decouple-vs-and-net-sdk.md index aa483c3afc7d..d2a201cd391e 100644 --- a/documentation/general/decouple-vs-and-net-sdk.md +++ b/documentation/general/decouple-vs-and-net-sdk.md @@ -119,6 +119,12 @@ Solutions that mix .NET SDK and Visual Studio projects will end up with multiple The compiler will offer a property that allows SDK projects to use the MSBuild version of the compiler when being built with `msbuild`: `Framework`. This can be added to a `Directory.Build.props` file to impact the entire solution. This is not expected to be a common scenario but is available for customers who need it. This property will be ignored when using `dotnet build` as there is no way to fall back to the Visual Studio compiler in that scenario. +> [!NOTE] +> These values are recognized for property `RoslynCompilerType`: +> - `Core`: use the compiler that comes with the .NET SDK +> - `Framework`: use the compiler that comes with .NET Framework MSBuild +> - `FrameworkPackage`: download package with .NET Framework compiler corresponding to the .NET SDK version + ### .NET Framework based analyzers There are a few analyzers which are built against .NET Framework TFMs. That means when loaded in a .NET Core compiler it could lead to compatibility issues. This is not expected to be a significant issue as our processes have been pushing customers to target `netstandard` in analyzers for 5+ years. However it is possible that some customers will run into issues here. From 4451c92976d4840ee0577adde85726fc6ea86897 Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Fri, 18 Apr 2025 15:27:06 -0700 Subject: [PATCH 14/15] roslyn code flow --- eng/Version.Details.xml | 44 ++++++++++++++++++++--------------------- eng/Versions.props | 19 +++++++++--------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 4139feb63708..61360565cb7a 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -120,47 +120,47 @@ 4ba36db1f42f33a66d9677f0b9d589d39b204a9c - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb - + https://github.com/dotnet/roslyn - c7525777ea55920c841e57cb084a76c2e05838d7 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb https://github.com/nuget/nuget.client @@ -462,9 +462,9 @@ https://github.com/dotnet/roslyn-analyzers cbcc6ddf3db6dedff5049f0397e1351951c13271 - + https://github.com/dotnet/roslyn - 959bcb76028fa383d6e1388c60bef630c75470d3 + 284e2d86b5458da3f1f0e53f8a55ca62801d9bbb diff --git a/eng/Versions.props b/eng/Versions.props index a60a2bc0a296..f4415f3eccca 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -221,15 +221,16 @@ - 4.14.0-3.25210.1 - 4.14.0-3.25210.1 - 4.14.0-3.25210.1 - 4.14.0-3.25210.1 - 4.14.0-3.25210.1 - 4.14.0-3.25210.1 - 4.14.0-3.25210.1 - 4.14.0-3.25210.1 - 4.14.0-3.25210.1 + 4.14.0-1.25218.2 + 4.14.0-1.25218.2 + 4.14.0-1.25218.2 + 4.14.0-1.25218.2 + 4.14.0-1.25218.2 + 4.14.0-1.25218.2 + 4.14.0-1.25218.2 + 4.14.0-1.25218.2 + 4.14.0-1.25218.2 + 3.12.0-beta1.25218.2 From 6c95106f271c745608451d37d4be763097311c90 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Sat, 19 Apr 2025 17:29:39 +0200 Subject: [PATCH 15/15] Remove temporary NuGet feed --- NuGet.config | 2 -- 1 file changed, 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index 6b864f946160..09870da28882 100644 --- a/NuGet.config +++ b/NuGet.config @@ -32,8 +32,6 @@ - -