Skip to content

Commit a0fb5ac

Browse files
authored
Merge pull request #616 from dotnet/fix615
Switch from PInvoke nuget dependency to CsWin32
2 parents 1902982 + 8cfe442 commit a0fb5ac

File tree

8 files changed

+29
-46
lines changed

8 files changed

+29
-46
lines changed

3rdPartyNotices.txt

-25
Original file line numberDiff line numberDiff line change
@@ -127,31 +127,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
127127
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
128128
SOFTWARE.
129129

130-
dotnet/PInvoke (https://github.com/dotnet/pinvoke)
131-
==============
132-
133-
MIT License
134-
135-
Copyright (c) .NET Foundation and Contributors
136-
137-
Permission is hereby granted, free of charge, to any person obtaining a copy
138-
of this software and associated documentation files (the "Software"), to deal
139-
in the Software without restriction, including without limitation the rights
140-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
141-
copies of the Software, and to permit persons to whom the Software is
142-
furnished to do so, subject to the following conditions:
143-
144-
The above copyright notice and this permission notice shall be included in all
145-
copies or substantial portions of the Software.
146-
147-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
148-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
149-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
150-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
151-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
152-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
153-
SOFTWARE.
154-
155130
Cake Contrib (https://github.com/cake-contrib/graphics)
156131
============
157132

azure-pipelines.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ stages:
5858
displayName: Configure git commit author for testing
5959
6060
- task: UseDotNet@2
61-
displayName: Install .NET Core SDK 5.0.202
61+
displayName: Install .NET Core 5.0.202 SDK
6262
inputs:
6363
packageType: sdk
6464
version: 5.0.202
6565

6666
- task: UseDotNet@2
67-
displayName: Install .NET Core 3.1
67+
displayName: Install .NET Core 3.1 runtime
6868
inputs:
6969
packageType: runtime
7070
version: 3.1.x
@@ -296,17 +296,17 @@ stages:
296296
vmImage: $(imageName)
297297
steps:
298298
- task: UseDotNet@2
299-
displayName: Install .NET Core SDK 2.1.811
299+
displayName: Install .NET Core 2.1 runtime
300300
inputs:
301-
packageType: sdk
302-
version: 2.1.811
301+
packageType: runtime
302+
version: 2.1.x
303303
- task: UseDotNet@2
304-
displayName: Install .NET Core SDK 3.1.100
304+
displayName: Install .NET Core 3.1 runtime
305305
inputs:
306-
packageType: sdk
307-
version: 3.1.100
306+
packageType: runtime
307+
version: 3.1.x
308308
- task: UseDotNet@2
309-
displayName: Install .NET Core SDK 5.0.202
309+
displayName: Install .NET Core 5.0.202 SDK
310310
inputs:
311311
packageType: sdk
312312
version: 5.0.202

src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
using System.IO;
66
using System.Runtime.InteropServices;
77
using Microsoft.Win32.SafeHandles;
8-
using static PInvoke.Kernel32;
9-
using FileShare = PInvoke.Kernel32.FileShare;
8+
using Windows.Win32;
9+
using Windows.Win32.Storage.FileSystem;
10+
using Windows.Win32.System.SystemServices;
1011

1112
namespace Nerdbank.GitVersioning.ManagedGit
1213
{
@@ -24,7 +25,7 @@ internal static bool TryOpen(string path, out FileStream? stream)
2425
{
2526
if (IsWindows)
2627
{
27-
var handle = CreateFile(path, ACCESS_MASK.GenericRight.GENERIC_READ, FileShare.FILE_SHARE_READ, (SECURITY_ATTRIBUTES?)null, CreationDisposition.OPEN_EXISTING, CreateFileFlags.FILE_ATTRIBUTE_NORMAL, SafeObjectHandle.Null);
28+
var handle = PInvoke.CreateFile(path, FILE_ACCESS_FLAGS.FILE_GENERIC_READ, FILE_SHARE_MODE.FILE_SHARE_READ, lpSecurityAttributes: null, FILE_CREATION_DISPOSITION.OPEN_EXISTING, FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_NORMAL, null);
2829

2930
if (!handle.IsInvalid)
3031
{
@@ -62,12 +63,15 @@ internal static unsafe bool TryOpen(ReadOnlySpan<char> path, [NotNullWhen(true)]
6263
{
6364
if (IsWindows)
6465
{
65-
var handle = CreateFile(path, ACCESS_MASK.GenericRight.GENERIC_READ, FileShare.FILE_SHARE_READ, null, CreationDisposition.OPEN_EXISTING, CreateFileFlags.FILE_ATTRIBUTE_NORMAL, SafeObjectHandle.Null);
66+
HANDLE handle;
67+
fixed (char* pPath = &path[0])
68+
{
69+
handle = PInvoke.CreateFile(pPath, FILE_ACCESS_FLAGS.FILE_GENERIC_READ, FILE_SHARE_MODE.FILE_SHARE_READ, null, FILE_CREATION_DISPOSITION.OPEN_EXISTING, FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_NORMAL, default);
70+
}
6671

67-
if (!handle.IsInvalid)
72+
if (!handle.Equals(Constants.INVALID_HANDLE_VALUE))
6873
{
69-
var fileHandle = new SafeFileHandle(handle.DangerousGetHandle(), ownsHandle: true);
70-
handle.SetHandleAsInvalid();
74+
var fileHandle = new SafeFileHandle(handle, ownsHandle: true);
7175
stream = new FileStream(fileHandle, System.IO.FileAccess.Read);
7276
return true;
7377
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$schema": "https://aka.ms/CsWin32.schema.json"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CreateFile
2+
INVALID_HANDLE_VALUE

src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<PackageReference Include="DotNetMDDocs" Version="0.111.0" PrivateAssets="all" Condition=" '$(GenerateMarkdownApiDocs)' == 'true' " />
1313
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0096" PrivateAssets="none" />
1414
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
15+
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.478-beta" PrivateAssets="all" />
1516
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
1617
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
1718
<PackageReference Include="Validation" Version="2.5.5-beta" />
1819
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.4.173-alpha" />
1920
<PackageReference Include="System.Text.Json" Version="4.7.2" />
20-
<PackageReference Include="PInvoke.Kernel32" Version="0.7.104" />
2121
</ItemGroup>
2222
<ItemGroup>
2323
<Compile Include="..\Shared\**\*.cs" LinkBase="Shared" />

src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.nuspec

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ IMPORTANT: The 3.x release may produce a different version height than prior maj
2323
<file src="$BaseOutputPath$net461\NerdBank.GitVersioning.dll" target="build\MSBuildFull\NerdBank.GitVersioning.dll" />
2424
<file src="$BaseOutputPath$net461\Nerdbank.GitVersioning.Tasks.dll" target="build\MSBuildFull\Nerdbank.GitVersioning.Tasks.dll" />
2525
<file src="$BaseOutputPath$net461\Newtonsoft.Json.dll" target="build\MSBuildFull\Newtonsoft.Json.dll" />
26-
<file src="$BaseOutputPath$net461\PInvoke.Kernel32.dll" target="build\MSBuildFull\PInvoke.Kernel32.dll" />
2726
<file src="$BaseOutputPath$net461\System.Buffers.dll" target="build\MSBuildFull\System.Buffers.dll" />
2827
<file src="$BaseOutputPath$net461\System.Memory.dll" target="build\MSBuildFull\System.Memory.dll" />
2928
<file src="$BaseOutputPath$net461\System.Numerics.Vectors.dll" target="build\MSBuildFull\System.Numerics.Vectors.dll" />
@@ -49,7 +48,6 @@ IMPORTANT: The 3.x release may produce a different version height than prior maj
4948
<file src="$BaseOutputPath$netcoreapp2.1\System.Text.Json.dll" target="build\MSBuildCore\System.Text.Json.dll" />
5049
<file src="$BaseOutputPath$netcoreapp2.1\Validation.dll" target="build\MSBuildCore\Validation.dll" />
5150
<file src="$BaseOutputPath$netcoreapp2.1\System.Runtime.CompilerServices.Unsafe.dll" target="build\MSBuildCore\System.Runtime.CompilerServices.Unsafe.dll" />
52-
<file src="$BaseOutputPath$netcoreapp2.1\PInvoke.Kernel32.dll" target="build\MSBuildCore\PInvoke.Kernel32.dll" />
5351

5452
<file src="build\Nerdbank.GitVersioning.targets" target="build\Nerdbank.GitVersioning$LKGSuffix$.targets" />
5553
<file src="build\Nerdbank.GitVersioning.Common.targets" target="build\Nerdbank.GitVersioning.Common.targets" />

src/Nerdbank.GitVersioning.sln

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.28404.58
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31411.2
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4BD1A7CD-6F52-4F5A-825B-50E4D8C3ECFF}"
77
ProjectSection(SolutionItems) = preProject
88
..\.editorconfig = ..\.editorconfig
99
..\.gitignore = ..\.gitignore
10+
..\3rdPartyNotices.txt = ..\3rdPartyNotices.txt
1011
..\azure-pipelines.yml = ..\azure-pipelines.yml
1112
..\build.ps1 = ..\build.ps1
1213
Directory.Build.props = Directory.Build.props

0 commit comments

Comments
 (0)