Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Basic.CompilerLog.Util" Version="0.9.9" />
Comment thread
baronfel marked this conversation as resolved.
<PackageVersion Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageVersion Include="FluentAssertions.Json" Version="$(FluentAssertionsJsonVersion)" />
<PackageVersion Include="Microsoft.ApplicationInsights" Version="$(MicrosoftApplicationInsightsPackageVersion)" />
Expand Down Expand Up @@ -75,6 +76,7 @@
<PackageVersion Include="Microsoft.Web.Xdt" Version="$(MicrosoftWebXdtPackageVersion)" />
<PackageVersion Include="Microsoft.Win32.SystemEvents" Version="$(MicrosoftWin32SystemEventsPackageVersion)" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="$(MicrosoftWindowsCsWin32PackageVersion)" />
<PackageVersion Include="MSBuild.StructuredLogger" Version="2.2.386" />
<PackageVersion Include="Moq" Version="$(MoqPackageVersion)" />
<PackageVersion Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
<PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
Expand Down
2 changes: 2 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<add key="richnav" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-buildservices/nuget/v3/index.json" />
<!-- mstest dependencies -->
<add key="test-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json" />
<!-- temporary for this PR until the corresponding Roslyn PR is merged -->
<add key="general-testing" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/general-testing/nuget/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />
Expand Down
40 changes: 20 additions & 20 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,47 +125,47 @@
<Sha>e165bbea9e27ceb4c8b91c22bd0c564ff1dc8b25</Sha>
<SourceBuild RepoName="fsharp" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
<SourceBuild RepoName="roslyn" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset.Framework" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.Net.Compilers.Toolset.Framework" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.CodeAnalysis" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.14.0-3.25179.1">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.14.0-3.25201.12">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>304768b76e90f5d224b745e3a03cfc5e9509baf6</Sha>
<Sha>f4c8c459d8dc8d779913d9711aa125c10f4e41b6</Sha>
</Dependency>
<Dependency Name="Microsoft.Build.NuGetSdkResolver" Version="6.14.0-preview.1.97">
<Uri>https://github.com/nuget/nuget.client</Uri>
Expand Down
18 changes: 9 additions & 9 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/roslyn -->
<MicrosoftNetCompilersToolsetVersion>4.14.0-3.25179.1</MicrosoftNetCompilersToolsetVersion>
<MicrosoftNetCompilersToolsetFrameworkPackageVersion>4.14.0-3.25179.1</MicrosoftNetCompilersToolsetFrameworkPackageVersion>
<MicrosoftCodeAnalysisPackageVersion>4.14.0-3.25179.1</MicrosoftCodeAnalysisPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.14.0-3.25179.1</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>4.14.0-3.25179.1</MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.14.0-3.25179.1</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.14.0-3.25179.1</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.14.0-3.25179.1</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.14.0-3.25179.1</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftNetCompilersToolsetVersion>4.14.0-3.25201.12</MicrosoftNetCompilersToolsetVersion>
<MicrosoftNetCompilersToolsetFrameworkPackageVersion>4.14.0-3.25201.12</MicrosoftNetCompilersToolsetFrameworkPackageVersion>
<MicrosoftCodeAnalysisPackageVersion>4.14.0-3.25201.12</MicrosoftCodeAnalysisPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.14.0-3.25201.12</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>4.14.0-3.25201.12</MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.14.0-3.25201.12</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.14.0-3.25201.12</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.14.0-3.25201.12</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.14.0-3.25201.12</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
Comment thread
jjonescz marked this conversation as resolved.
Outdated
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/aspnet/AspNetCore -->
Expand Down
2 changes: 2 additions & 0 deletions sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,22 @@ Copyright (c) .NET Foundation. All rights reserved.
<IsNetCoreAppTargetingLatestTFM Condition="'$(IsNetCoreAppTargetingLatestTFM)' == '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(_TargetFrameworkVersionWithoutV)' == '$(NETCoreAppMaximumVersion)'">true</IsNetCoreAppTargetingLatestTFM>
</PropertyGroup>

<!--
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.
-->
<PropertyGroup>
<RoslynUseSdkCompiler Condition="'$(RoslynUseSdkCompiler)' == '' and
'$(RoslynUseMSBuildCompiler)' != 'true' and
'$(BuildWithNetFrameworkHostedCompiler)' != 'true' and
('$(DOTNET_HOST_PATH)' != '' or '$(DOTNET_EXPERIMENTAL_HOST_PATH)' != '')">true</RoslynUseSdkCompiler>
Comment thread
jjonescz marked this conversation as resolved.
Outdated
</PropertyGroup>
<PropertyGroup Condition="'$(RoslynUseSdkCompiler)' == 'true'">
<RoslynTargetsPath Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\..\..\Roslyn</RoslynTargetsPath>
<RoslynTargetsPath Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\..\..\Roslyn\binfx</RoslynTargetsPath>
Comment thread
jjonescz marked this conversation as resolved.
<RoslynToolsDirectory Condition="'$(MSBuildRuntimeType)' != 'Core'">..\bincore</RoslynToolsDirectory>
Comment thread
jjonescz marked this conversation as resolved.
Outdated
<CSharpCoreTargetsPath>$(MSBuildThisFileDirectory)..\..\..\Roslyn\Microsoft.CSharp.Core.targets</CSharpCoreTargetsPath>
<VisualBasicCoreTargetsPath>$(MSBuildThisFileDirectory)..\..\..\Roslyn\Microsoft.VisualBasic.Core.targets</VisualBasicCoreTargetsPath>
</PropertyGroup>

</Project>
Comment thread
jjonescz marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Basic.CompilerLog.Util" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.Build" />
<PackageReference Include="MSBuild.StructuredLogger" />
<PackageReference Include="NuGet.ProjectModel" />
<PackageReference Include="NuGet.LibraryModel" />
<PackageReference Include="NuGet.Versioning" />
<PackageReference Include="NuGet.Configuration" />
<PackageReference Include="NuGet.Frameworks" />
<PackageReference Include="NuGet.Common" />
<PackageReference Include="Xunit.Combinatorial" />
</ItemGroup>

<ItemGroup>
Expand Down
128 changes: 128 additions & 0 deletions test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs
Original file line number Diff line number Diff line change
@@ -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<TestProject>? 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";
}
Comment on lines +74 to +78

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.

Might be simpler to just always be explicit here:

Suggested change
// UseSharedCompilation should be the default, so set it only if false.
if (!useSharedCompilation)
{
project.AdditionalProperties["UseSharedCompilation"] = "false";
}
project.AdditionalProperties["UseSharedCompilation"] = useSharedCompilation ? "true" : "false";

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.

Which you can probably fold into the initializer above actually

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.

My intention is to not set UseSharedCompilation to true, so the tests also verify that true is the default value


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.GetOutputDirectory().File(testAsset.TestProject!.GetOutputFileName()));

return buildCommand;
}

private TestCommand BuildAndRunUsingDotNet(TestAsset testAsset)
{
var buildCommand = new DotnetBuildCommand(testAsset);
buildCommand.Execute("-bl").Should().Pass();

Run(buildCommand.GetOutputDirectory().File(testAsset.TestProject!.GetOutputFileName()));

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<Message>(
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");
}
}
14 changes: 14 additions & 0 deletions test/Microsoft.NET.TestFramework/Commands/DotnetBuildCommand.cs
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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);
Expand All @@ -22,5 +28,13 @@ 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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
}
}