Skip to content

Commit f9d9b3e

Browse files
Fix CLI test compilation error - construct assembly path dynamically
- Remove direct typeof(ProcessIdTask) reference that caused CS0234 error - Construct path to Microsoft.Build.Engine.UnitTests.dll dynamically at runtime - Use Assembly.GetExecutingAssembly().Location and Path.Combine - Add necessary using statements (System.IO, System.Reflection) - This avoids compile-time dependency on ProcessIdTask type Co-authored-by: YuliiaKovalova <[email protected]>
1 parent 52434d5 commit f9d9b3e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/MSBuild.UnitTests/DotNetRuntimeTask_CLI_Tests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
4+
using System.IO;
5+
using System.Reflection;
56
using Microsoft.Build.UnitTests.Shared;
67
using Shouldly;
78
using Xunit;
@@ -36,8 +37,11 @@ public void MSBuildCLI_WithDotNetRuntimeTask_ShowsClearError()
3637
using (var env = TestEnvironment.Create(_output))
3738
{
3839
// Use the same ProcessIdTask from Microsoft.Build.Engine.UnitTests that is built during the repo build
39-
// Get the path to the Microsoft.Build.Engine.UnitTests assembly
40-
string taskAssemblyPath = typeof(Microsoft.Build.UnitTests.ProcessIdTask).Assembly.Location;
40+
// Construct the path to the Microsoft.Build.Engine.UnitTests assembly dynamically
41+
// since we don't have a direct reference to it from this test project
42+
string currentAssemblyPath = Assembly.GetExecutingAssembly().Location;
43+
string currentDirectory = Path.GetDirectoryName(currentAssemblyPath)!;
44+
string taskAssemblyPath = Path.Combine(currentDirectory, "Microsoft.Build.Engine.UnitTests.dll");
4145

4246
string projectContent = $@"
4347
<Project>

0 commit comments

Comments
 (0)