8000 Support launching net taskhost - initial implementation (#11393) · dotnet/msbuild@0e2431a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e2431a

Browse files
Support launching net taskhost - initial implementation (#11393)
1 parent 822ba23 commit 0e2431a

31 files changed

+654
-229
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# editorconfig.org
1+
# editorconfig.org
22

33
# top-most EditorConfig file
44
root = true

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<NuGetBuildTasksVersion>6.15.0-preview.1.86</NuGetBuildTasksVersion>
8585
<MicrosoftNetCompilersToolsetVersion>5.0.0-1.25321.2</MicrosoftNetCompilersToolsetVersion>
8686
</PropertyGroup>
87-
<PropertyGroup Condition="!$(TargetFramework.StartsWith('net4'))">
87+
<PropertyGroup>
8888
<BootstrapSdkVersion>9.0.301</BootstrapSdkVersion>
8989
</PropertyGroup>
9090
<Target Name="OverrideArcadeFileVersion" AfterTargets="_InitializeAssemblyVersion">

src/Build.UnitTests/BackEnd/BuildManager_Tests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,9 +1136,9 @@ public void PendGraphBuildRequestWithoutBegin()
11361136
public void EndWithoutBegin()
11371137
{
11381138
Assert.Throws<InvalidOperationException>(() =>
1139-
{
1140-
_buildManager.EndBuild();
1141-
});
1139+
{
1140+
_buildManager.EndBuild();
1141+
});
11421142
}
11431143

11441144
[Fact]

src/Build.UnitTests/BackEnd/TaskHostConfiguration_Tests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void ConstructorWithNullName()
3838
Assert.Throws<InternalErrorException>(() =>
3939
{
4040
TaskHostConfiguration config = new TaskHostConfiguration(
41+
runtime: "TaskHost",
4142
nodeId: 1,
4243
startupDirectory: Directory.GetCurrentDirectory(),
4344
buildProcessEnvironment: null,
@@ -73,6 +74,7 @@ public void ConstructorWithEmptyName()
7374
Assert.Throws<InternalErrorException>(() =>
7475
{
7576
TaskHostConfiguration config = new TaskHostConfiguration(
77+
runtime: "TaskHost",
7678
nodeId: 1,
7779
startupDirectory: Directory.GetCurrentDirectory(),
7880
buildProcessEnvironment: null,
@@ -108,6 +110,7 @@ public void ConstructorWithNullLocation()
108110
Assert.Throws<InternalErrorException>(() =>
109111
{
110112
TaskHostConfiguration config = new TaskHostConfiguration(
113+
runtime: "TaskHost",
111114
nodeId: 1,
112115
startupDirectory: Directory.GetCurrentDirectory(),
113116
buildProcessEnvironment: null,
@@ -145,6 +148,7 @@ public void ConstructorWithEmptyLocation()
145148
Assert.Throws<InternalErrorException>(() =>
146149
{
147150
TaskHostConfiguration config = new TaskHostConfiguration(
151+
runtime: "TaskHost",
148152
nodeId: 1,
149153
startupDirectory: Directory.GetCurrentDirectory(),
150154
buildProcessEnvironment: null,
@@ -180,6 +184,7 @@ public void ConstructorWithEmptyLocation()
180184
public void TestValidConstructors()
181185
{
182186
TaskHostConfiguration config = new TaskHostConfiguration(
187+
runtime: "TaskHost",
183188
nodeId: 1,
184189
startupDirectory: Directory.GetCurrentDirectory(),
185190
buildProcessEnvironment: null,
@@ -206,6 +211,7 @@ public void TestValidConstructors()
206211
warningsAsMessages: null);
207212

208213
TaskHostConfiguration config2 = new TaskHostConfiguration(
214+
runtime: "TaskHost",
209215
nodeId: 1,
210216
startupDirectory: Directory.GetCurrentDirectory(),
211217
buildProcessEnvironment: null,
@@ -233,6 +239,7 @@ public void TestValidConstructors()
233239

234240
IDictionary<string, object> parameters = new Dictionary<string, object>();
235241
TaskHostConfiguration config3 = new TaskHostConfiguration(
242+
runtime: "TaskHost",
236243
nodeId: 1,
237244
startupDirectory: Directory.GetCurrentDirectory(),
238245
buildProcessEnvironment: null,
@@ -265,6 +272,7 @@ public void TestValidConstructors()
265272
parameters2.Add("ItemArray", new ITaskItem[] { new TaskItem("DEF"), new TaskItem("GHI"), new TaskItem("JKL") });
266273

267274
TaskHostConfiguration config4 = new TaskHostConfiguration(
275+
runtime: "TaskHost",
268276
nodeId: 1,
269277
startupDirectory: Directory.GetCurrentDirectory(),
270278
buildProcessEnvironment: null,
@@ -297,6 +305,7 @@ public void TestValidConstructors()
297305
WarningsAsErrors.Add("MSB1237");
298306

299307
TaskHostConfiguration config5 = new TaskHostConfiguration(
308+
runtime: "TaskHost",
300309
nodeId: 1,
301310
startupDirectory: Directory.GetCurrentDirectory(),
302311
buildProcessEnvironment: null,
@@ -336,6 +345,7 @@ public void TestTranslationWithNullDictionary()
336345
};
337346

338347
TaskHostConfiguration config = new TaskHostConfiguration(
348+
runtime: "TaskHost",
339349
nodeId: 1,
340350
startupDirectory: Directory.GetCurrentDirectory(),
341351
buildProcessEnvironment: null,
@@ -387,6 +397,7 @@ public void TestTranslationWithAppDomainSetup(byte[] configBytes)
387397
AppDomainSetup setup = new AppDomainSetup();
388398

389399
TaskHostConfiguration config = new TaskHostConfiguration(
400+
runtime: "TaskHost",
390401
nodeId: 1,
391402
startupDirectory: Directory.GetCurrentDirectory(),
392403
buildProcessEnvironment: null,
@@ -433,6 +444,7 @@ public void TestTranslationWithAppDomainSetup(byte[] configBytes)
433444
public void TestTranslationWithEmptyDictionary()
434445
{
435446
TaskHostConfiguration config = new TaskHostConfiguration(
447+
runtime: "TaskHost",
436448
nodeId: 1,
437449
startupDirectory: Directory.GetCurrentDirectory(),
438450
buildProcessEnvironment: null,
@@ -484,6 +496,7 @@ public void TestTranslationWithValueTypesInDictionary()
484496
parameters.Add("Text", "Foo");
485497
parameters.Add("BoolValue", false);
486498
TaskHostConfiguration config = new TaskHostConfiguration(
499+
runtime: "TaskHost",
487500
nodeId: 1,
488501
startupDirectory: Directory.GetCurrentDirectory(),
489502
buildProcessEnvironment: null,
@@ -533,6 +546,7 @@ public void TestTranslationWithITaskItemInDictionary()
533546
IDictionary<string, object> parameters = new Dictionary<string, object>();
534547
parameters.Add("TaskItemValue", new TaskItem("Foo"));
535548
TaskHostConfiguration config = new TaskHostConfiguration(
549+
runtime: "TaskHost",
536550
nodeId: 1,
537551
startupDirectory: Directory.GetCurrentDirectory(),
538552
buildProcessEnvironment: null,
@@ -581,6 +595,7 @@ public void TestTranslationWithITaskItemArrayInDictionary()
581595
IDictionary<string, object> parameters = new Dictionary<string, object>();
582596
parameters.Add("TaskItemArrayValue", new ITaskItem[] { new TaskItem("Foo"), new TaskItem("Baz") });
583597
TaskHostConfiguration config = new TaskHostConfiguration(
598+
runtime: "TaskHost",
584599
nodeId: 1,
585600
startupDirectory: Directory.GetCurrentDirectory(),
586601
buildProcessEnvironment: null,
@@ -636,6 +651,7 @@ public void TestTranslationWithWarningsAsErrors()
636651
WarningsAsErrors.Add("MSB1236");
637652
WarningsAsErrors.Add("MSB1237");
638653
TaskHostConfiguration config = new TaskHostConfiguration(
654+
runtime: "TaskHost",
639655
nodeId: 1,
640656
startupDirectory: Directory.GetCurrentDirectory(),
641657
buildProcessEnvironment: null,
@@ -686,6 +702,7 @@ public void TestTranslationWithWarningsAsMessages()
686702
WarningsAsMessages.Add("MSB1236");
687703
WarningsAsMessages.Add("MSB1237");
688704
TaskHostConfiguration config = new TaskHostConfiguration(
705+
runtime: "TaskHost",
689706
nodeId: 1,
690707
startupDirectory: Directory.GetCurrentDirectory(),
691708
buildProcessEnvironment: null,

src/Build.UnitTests/Instance/TaskItem_Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,4 @@ public void Escaping3()
371371
logger.AssertLogContains("i1%2ai2");
372372
}
373373
}
374-
}
374+
}

src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@
8888
<None Include="..\Shared\UnitTests\xunit.runner.json">
8989
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9090
</None>
91+
<None Include="TestAssets\**\*">
92+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
93+
</None>
9194
</ItemGroup>
9295

9396
<Target Name="CopyTestProjects" AfterTargets="ResolveProjectReferences">
@@ -122,6 +125,10 @@
122125
</Content>
123126
</ItemDefinitionGroup>
124127

128+
<ItemGroup Label="TestAssests" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
129+
<ProjectReference Include=".\TestAssets\ExampleNetTask\ExampleTask\ExampleTask.csproj" />
130+
</ItemGroup>
131+
125132
<ItemGroup>
126133
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
127134
</ItemGroup>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.IO;
6+
using Microsoft.Build.Internal;
7+
using Microsoft.Build.UnitTests;
8+
using Microsoft.Build.UnitTests.Shared;
9+
using Shouldly;
10+
using Xunit;
11+
12+
namespace Microsoft.Build.Engine.UnitTests
13+
{
14+
public class NetTaskHost_E2E_Tests
15+
{
16+
private static string AssemblyLocation { get; } = Path.Combine(Path.GetDirectoryName(typeof(NetTaskHost_E2E_Tests).Assembly.Location) ?? AppContext.BaseDirectory);
17+
18+
private static string TestAssetsRootPath { get; } = Path.Combine(AssemblyLocation, "TestAssets");
19+
20+
[WindowsFullFrameworkOnlyFact]
21+
public void NetTaskHostTest()
22+
{
23+
using TestEnvironment env = TestEnvironment.Create();
24+
var bootstrapCoreFolder = Path.Combine(RunnerUtilities.BootstrapRootPath, "core");
25+
_ = env.SetEnvironmentVariable("MSBuildToolsDirectoryNET", Path.Combine(RunnerUtilities.BootstrapRootPath, "core"));
26+
_ = env.SetEnvironmentVariable("MSBuildAssemblyDirectory", Path.Combine(RunnerUtilities.BootstrapRootPath, "core", "sdk", RunnerUtilities.BootstrapSdkVersion));
27+
28+
string testProjectPath = Path.Combine(TestAssetsRootPath, "ExampleNetTask", "TestNetTask", "TestNetTask.csproj");
29+
30+
string testTaskOutput = RunnerUtilities.ExecBootstrapedMSBuild($"{testProjectPath} -restore -v:m", out bool successTestTask);
31+
successTestTask.ShouldBeTrue();
32+
33+
testTaskOutput.ShouldContain($"The task is executed in process: dotnet");
34+
testTaskOutput.ShouldContain($"Process path: {Path.Combine(bootstrapCoreFolder, Constants.DotnetProcessName)}");
35+
}
36+
}
37+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
using System.Diagnostics;
4+
using Microsoft.Build.Framework;
5+
6+
namespace NetTask
7+
{
8+
public class ExampleTask : Microsoft.Build.Utilities.Task
9+
{
10+
public override bool Execute()
11+
{
12+
try
13+
{
14+
var currentProcess = Process.GetCurrentProcess();
15+
var executingProcess = currentProcess.ProcessName;
16+
var processPath = currentProcess.MainModule?.FileName ?? "Unknown";
17+
18+
Log.LogMessage(MessageImportance.High, $"The task is executed in process: {executingProcess}");
19+
Log.LogMessage(MessageImportance.High, $"Process path: {processPath}");
20+
21+
return true;
22+
}
23+
catch (System.Exception ex)
24+
{
25+
Log.LogError($"Failed to determine executing process: {ex.Message}");
26+
return false;
27+
}
28+
}
29+
}
30+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.Build.Framework" />
9+
<PackageReference Include="Microsoft.Build.Utilities.Core" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageVersion Include="Microsoft.Build.Framework" Version="17.0.0" />
14+
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.0.0" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<TestProjectFolder>$([System.IO.Path]::GetFullPath('$([System.IO.Path]::Combine('$(AssemblyLocation)', '..'))'))</TestProjectFolder>
9+
<ExampleTaskPath>$([System.IO.Path]::Combine('$(TestProjectFolder)', '$(TargetFramework)', 'ExampleTask.dll'))</ExampleTaskPath>
10+
</PropertyGroup>
11+
12+
<UsingTask
13+
TaskName="ExampleTask"
14+
AssemblyFile="$(ExampleTaskPath)"
15+
Runtime="NET"/>
16+
17+
<Target Name="TestTask" BeforeTargets="Build">
18+
<ExampleTask />
19+
</Target>
20+
21+
</Project>

0 commit comments

Comments
 (0)
0