Skip to content

Commit 1e7e7aa

Browse files
authored
Remove System.Management dependency (#665)
* remove System.Management * Update WindowsProcessTests.cs * LibraryImport
1 parent ff5f9f7 commit 1e7e7aa

File tree

5 files changed

+394
-26
lines changed

5 files changed

+394
-26
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
global using EmptyFiles;
1+
global using EmptyFiles;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#if NET5_0_OR_GREATER
2+
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
3+
#endif
4+
public class WindowsProcessTests(ITestOutputHelper output) :
5+
XunitContextBase(output)
6+
{
7+
[Theory]
8+
[InlineData("\"C:\\Program Files\\Beyond Compare 4\\BComp.exe\" C:\\temp\\file.1.txt C:\\temp\\file.2.txt", true)]
9+
[InlineData("notepad.exe C:\\Users\\test\\doc.1.txt C:\\Users\\test\\doc.2.txt", true)]
10+
[InlineData("\"C:\\diff\\tool.exe\" D:\\path\\to\\source.1.cs D:\\path\\to\\target.2.cs", true)]
11+
[InlineData("code.exe --diff file.a.b file.c.d", true)]
12+
[InlineData("app.exe path.with.dots path.more.dots", true)]
13+
public void MatchesPattern_WithTwoFilePaths_ReturnsTrue(string commandLine, bool expected)
14+
{
15+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
16+
{
17+
return;
18+
}
19+
20+
Assert.Equal(expected, WindowsProcess.MatchesPattern(commandLine));
21+
}
22+
23+
[Theory]
24+
[InlineData("notepad.exe")]
25+
[InlineData("notepad.exe C:\\temp\\file.txt")]
26+
[InlineData("cmd.exe /c dir")]
27+
[InlineData("explorer.exe")]
28+
[InlineData("")]
29+
[InlineData("singleword")]
30+
[InlineData("app.exe onepath.with.dots")]
31+
public void MatchesPattern_WithoutTwoFilePaths_ReturnsFalse(string commandLine)
32+
{
33+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
34+
{
35+
return;
36+
}
37+
38+
Assert.False(WindowsProcess.MatchesPattern(commandLine));
39+
}
40+
41+
[Fact]
42+
public void FindAll_ReturnsProcessCommands()
43+
{
44+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
45+
{
46+
return;
47+
}
48+
49+
var result = WindowsProcess.FindAll();
50+
Assert.NotNull(result);
51+
foreach (var cmd in result)
52+
{
53+
Debug.WriteLine($"{cmd.Process}: {cmd.Command}");
54+
}
55+
}
56+
}

src/DiffEngine/DiffEngine.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
<PropertyGroup>
33
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net462;net472;net48;net9.0;net10.0</TargetFrameworks>
44
<TargetFrameworks>$(TargetFrameworks);net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
5+
<AllowUnsafeBlocks Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</AllowUnsafeBlocks>
56
</PropertyGroup>
67
<ItemGroup>
78
<Using Include="DiffEngine" />
8-
<Using Include="System.Management" />
9+
<Using Include="System.Text" />
910
<Using Include="Microsoft.Win32.SafeHandles" />
1011
<Using Include="System.Diagnostics.CodeAnalysis" />
1112
<Using Include="System.Net" />
@@ -19,10 +20,6 @@
1920
<PackageReference Include="EmptyFiles" PrivateAssets="None" />
2021
<PackageReference Include="Fody" PrivateAssets="all" />
2122
<PackageReference Include="Polyfill" PrivateAssets="all" />
22-
<PackageReference Include="System.Management" />
2323
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
2424
</ItemGroup>
25-
<Target Name="CheckPackageVersion" BeforeTargets="Build">
26-
<Error Condition="'%(PackageVersion.Identity)' == 'System.Management' AND '%(PackageVersion.Version)' != '8.0.0'" Text="Invalid package version for System.Management. Expected: 8.0.0." />
27-
</Target>
2825
</Project>

0 commit comments

Comments
 (0)