Skip to content

Commit e79ab14

Browse files
committed
squashed: Execute core compiler from full framework msbuild
1 parent 304768b commit e79ab14

20 files changed

+172
-58
lines changed

.vscode/launch.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,51 @@
6262
"stopAtEntry": false,
6363
"console": "internalConsole"
6464
},
65+
{
66+
"name": "Launch Microsoft.Build.Tasks.CodeAnalysis.dll via MSBuild.exe (netfx)",
67+
"type": "clr",
68+
"request": "launch",
69+
"preLaunchTask": "build toolset",
70+
"program": "C:/Program Files/Microsoft Visual Studio/2022/Preview/MSBuild/Current/Bin/amd64/MSBuild.exe",
71+
"args": [
72+
"-restore",
73+
"-p:RoslynTargetsPath=${workspaceFolder}/artifacts/bin/Microsoft.Net.Compilers.Toolset.Package/Debug/tasks/net472",
74+
],
75+
// A simple project that can be used to debug the build tasks against.
76+
"cwd": "${workspaceFolder}/src/Tools/Source/CompilerGeneratorTools/Source/BoundTreeGenerator",
77+
"stopAtEntry": false,
78+
"console": "internalConsole"
79+
},
80+
{
81+
"name": "Launch Microsoft.Build.Tasks.CodeAnalysis.dll via MSBuild.exe (netcore)",
82+
"type": "clr",
83+
"request": "launch",
84+
"preLaunchTask": "build toolset",
85+
"program": "C:/Program Files/Microsoft Visual Studio/2022/Preview/MSBuild/Current/Bin/amd64/MSBuild.exe",
86+
"args": [
87+
"-restore",
88+
"-p:RoslynTargetsPath=${workspaceFolder}/artifacts/bin/Microsoft.Net.Compilers.Toolset.Package/Debug/tasks/netcore",
89+
],
90+
// A simple project that can be used to debug the build tasks against.
91+
"cwd": "${workspaceFolder}/src/Tools/Source/CompilerGeneratorTools/Source/BoundTreeGenerator",
92+
"stopAtEntry": false,
93+
"console": "internalConsole"
94+
},
95+
{
96+
"name": "Launch Microsoft.Build.Tasks.CodeAnalysis.dll via dotnet build",
97+
"type": "coreclr",
98+
"request": "launch",
99+
"preLaunchTask": "build toolset",
100+
"program": "dotnet",
101+
"args": [
102+
"build",
103+
"-p:RoslynTargetsPath=${workspaceFolder}/artifacts/bin/Microsoft.Net.Compilers.Toolset.Package/Debug/tasks/netcore",
104+
],
105+
// A simple project that can be used to debug the build tasks against.
106+
"cwd": "${workspaceFolder}/src/Tools/Source/CompilerGeneratorTools/Source/BoundTreeGenerator",
107+
"stopAtEntry": false,
108+
"console": "internalConsole"
109+
},
65110
{
66111
"name": ".NET Core Launch (console)",
67112
"type": "coreclr",

.vscode/tasks.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@
9797
"problemMatcher": "$msCompile",
9898
"group": "build"
9999
},
100+
{
101+
"label": "build toolset",
102+
"type": "shell",
103+
"command": "dotnet",
104+
"args": [
105+
"build",
106+
"-p:GenerateFullPaths=true",
107+
"${workspaceFolder}/src/NuGet/Microsoft.Net.Compilers.Toolset/AnyCpu/Microsoft.Net.Compilers.Toolset.Package.csproj"
108+
],
109+
"problemMatcher": "$msCompile",
110+
"group": "build"
111+
},
100112
{
101113
"label": "msbuild current project",
102114
"type": "shell",

src/Compilers/Core/CommandLine/NativeMethods.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Runtime.InteropServices;
7+
using System.Runtime.Versioning;
78
using System.Text;
89

910
namespace Microsoft.CodeAnalysis.CommandLine
@@ -43,6 +44,9 @@ internal struct PROCESS_INFORMATION
4344
/// <summary>
4445
/// Interop methods.
4546
/// </summary>
47+
#if NET
48+
[SupportedOSPlatform("windows")]
49+
#endif
4650
internal static class NativeMethods
4751
{
4852
#region Constants

src/Compilers/Core/MSBuildTask/InteractiveCompiler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Microsoft.CodeAnalysis.BuildTasks
1212
{
1313
/// <summary>
14-
/// This class defines all of the common stuff that is shared between the Vbc and Csc tasks.
14+
/// This class defines all of the common stuff that is shared between the Vbi and Csi tasks.
1515
/// This class is not instantiatable as a Task just by itself.
1616
/// </summary>
1717
public abstract class InteractiveCompiler : ManagedToolTask
@@ -184,6 +184,8 @@ public ITaskItem? Source
184184

185185
#region Tool Members
186186

187+
protected override string? GetToolsDirectory() => null;
188+
187189
protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
188190
{
189191
if (ProvideCommandLineArgs)

src/Compilers/Core/MSBuildTask/ManagedCompiler.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,14 @@ public bool ReportIVTs
487487
get { return _store.GetOrDefault(nameof(ReportIVTs), false); }
488488
}
489489

490+
public string? ToolsDirectory
491+
{
492+
set { _store[nameof(ToolsDirectory)] = value; }
493+
get { return (string?)_store[nameof(ToolsDirectory)]; }
494+
}
495+
496+
protected override string? GetToolsDirectory() => ToolsDirectory;
497+
490498
#endregion
491499

492500
/// <summary>

src/Compilers/Core/MSBuildTask/ManagedToolTask.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ public abstract class ManagedToolTask : ToolTask
2828
/// </remarks>
2929
protected bool IsManagedTool => string.IsNullOrEmpty(ToolPath) && ToolExe == ToolName;
3030

31-
internal string PathToManagedTool => Utilities.GenerateFullPathToTool(ToolName);
31+
/// <summary>
32+
/// The directory where the tools (like csc) are located.
33+
/// Can be an absolute path or a path relative to the build tasks assembly.
34+
/// If <see langword="null"/>, the directory of the build tasks assembly is used on desktop runtime
35+
/// and its <c>bincore</c> subdirectory is used on core runtime.
36+
/// See <see cref="Utilities.GenerateFullPathToTool"/>.
37+
/// </summary>
38+
protected abstract string? GetToolsDirectory();
39+
40+
internal string PathToManagedTool => Utilities.GenerateFullPathToTool(ToolName, GetToolsDirectory());
3241

3342
private string PathToManagedToolWithoutExtension
3443
{

src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
TargetFramework="$(TargetFramework)"
154154
ToolExe="$(CscToolExe)"
155155
ToolPath="$(CscToolPath)"
156+
ToolsDirectory="$(RoslynToolsDirectory)"
156157
TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
157158
UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)"
158159
UseSharedCompilation="$(UseSharedCompilation)"

src/Compilers/Core/MSBuildTask/Microsoft.Managed.Core.targets

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
33
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
4+
<PropertyGroup>
5+
<_BuildTasksDirectory>$(MSBuildThisFileDirectory)</_BuildTasksDirectory>
6+
<_BuildTasksDirectory Condition="Exists('$(RoslynTargetsPath)')">$(RoslynTargetsPath)\</_BuildTasksDirectory>
7+
</PropertyGroup>
8+
49
<!--
510
Common targets for managed compilers.
611
-->
7-
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.MapSourceRoots" AssemblyFile="$(MSBuildThisFileDirectory)Microsoft.Build.Tasks.CodeAnalysis.dll" />
12+
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.MapSourceRoots" AssemblyFile="$(_BuildTasksDirectory)Microsoft.Build.Tasks.CodeAnalysis.dll" />
813

914
<Import Project="Microsoft.Managed.Core.CurrentVersions.targets" />
1015

@@ -58,7 +63,7 @@
5863
========================
5964
6065
-->
61-
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.ShowMessageForImplicitlySkipAnalyzers" AssemblyFile="$(MSBuildThisFileDirectory)Microsoft.Build.Tasks.CodeAnalysis.dll" />
66+
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.ShowMessageForImplicitlySkipAnalyzers" AssemblyFile="$(_BuildTasksDirectory)Microsoft.Build.Tasks.CodeAnalysis.dll" />
6267

6368
<Target Name="_ComputeSkipAnalyzers" BeforeTargets="CoreCompile">
6469
<!-- First, force clear non-user facing properties '_SkipAnalyzers' and '_ImplicitlySkipAnalyzers'. -->
@@ -151,7 +156,7 @@
151156
<CompilerVisibleProperty Include="PropertyNameToEval" />
152157
<CompilerVisibleItemMetadata Include="ItemType" MetadataName="MetadataToRetrieve" />
153158
-->
154-
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.GenerateMSBuildEditorConfig" AssemblyFile="$(MSBuildThisFileDirectory)Microsoft.Build.Tasks.CodeAnalysis.dll" />
159+
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.GenerateMSBuildEditorConfig" AssemblyFile="$(_BuildTasksDirectory)Microsoft.Build.Tasks.CodeAnalysis.dll" />
155160

156161
<Target Name="GenerateMSBuildEditorConfigFile"
157162
BeforeTargets="BeforeCompile;CoreCompile"

src/Compilers/Core/MSBuildTask/Microsoft.VisualBasic.Core.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
TargetFramework="$(TargetFramework)"
118118
ToolExe="$(VbcToolExe)"
119119
ToolPath="$(VbcToolPath)"
120+
ToolsDirectory="$(RoslynToolsDirectory)"
120121
TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
121122
UseHostCompilerIfAvailable="$(UseHostCompilerIfAvailable)"
122123
UseSharedCompilation="$(UseSharedCompilation)"

src/Compilers/Core/MSBuildTask/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This MSBuild tasks contains the core tasks and targets for compiling C# and VB p
44

55
## Debugging
66

7+
> [!NOTE] In VSCode, you can use one of the `Microsoft.Build.Tasks.CodeAnalysis.dll` launch targets.
8+
79
Debugging this code requires a bit of setup because it's not an independent component. It relies on having other parts of the toolset deployed in the same directory. Additionally the project being debugged needs to be modified to ensure this DLL is built instead of the one that ships along side MSBuild.
810

911
Set the startup project to Toolset. This project properly deploys all of the necessary components and hence provides a simple F5 experience.
@@ -26,9 +28,3 @@ The target project itself needs to be modified so that it will load the freshly
2628
Replace `e:\dd\roslyn` with the path to your Roslyn enlistment.
2729

2830
Once that is all done you should be able to F5 the Toolset project and debug the MSBuild task directly.
29-
30-
31-
32-
33-
34-

0 commit comments

Comments
 (0)