Skip to content

Commit

Permalink
Merge pull request #616 from dotnet/fix615
Browse files Browse the repository at this point in the history
Switch from PInvoke nuget dependency to CsWin32
  • Loading branch information
AArnott authored Jun 13, 2021
2 parents 1902982 + 8cfe442 commit a0fb5ac
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 46 deletions.
25 changes: 0 additions & 25 deletions 3rdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,31 +127,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

dotnet/PInvoke (https://github.com/dotnet/pinvoke)
==============

MIT License

Copyright (c) .NET Foundation and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Cake Contrib (https://github.com/cake-contrib/graphics)
============

Expand Down
18 changes: 9 additions & 9 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ stages:
displayName: Configure git commit author for testing
- task: UseDotNet@2
displayName: Install .NET Core SDK 5.0.202
displayName: Install .NET Core 5.0.202 SDK
inputs:
packageType: sdk
version: 5.0.202

- task: UseDotNet@2
displayName: Install .NET Core 3.1
displayName: Install .NET Core 3.1 runtime
inputs:
packageType: runtime
version: 3.1.x
Expand Down Expand Up @@ -296,17 +296,17 @@ stages:
vmImage: $(imageName)
steps:
- task: UseDotNet@2
displayName: Install .NET Core SDK 2.1.811
displayName: Install .NET Core 2.1 runtime
inputs:
packageType: sdk
version: 2.1.811
packageType: runtime
version: 2.1.x
- task: UseDotNet@2
displayName: Install .NET Core SDK 3.1.100
displayName: Install .NET Core 3.1 runtime
inputs:
packageType: sdk
version: 3.1.100
packageType: runtime
version: 3.1.x
- task: UseDotNet@2
displayName: Install .NET Core SDK 5.0.202
displayName: Install .NET Core 5.0.202 SDK
inputs:
packageType: sdk
version: 5.0.202
Expand Down
18 changes: 11 additions & 7 deletions src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using static PInvoke.Kernel32;
using FileShare = PInvoke.Kernel32.FileShare;
using Windows.Win32;
using Windows.Win32.Storage.FileSystem;
using Windows.Win32.System.SystemServices;

namespace Nerdbank.GitVersioning.ManagedGit
{
Expand All @@ -24,7 +25,7 @@ internal static bool TryOpen(string path, out FileStream? stream)
{
if (IsWindows)
{
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);
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);

if (!handle.IsInvalid)
{
Expand Down Expand Up @@ -62,12 +63,15 @@ internal static unsafe bool TryOpen(ReadOnlySpan<char> path, [NotNullWhen(true)]
{
if (IsWindows)
{
var handle = CreateFile(path, ACCESS_MASK.GenericRight.GENERIC_READ, FileShare.FILE_SHARE_READ, null, CreationDisposition.OPEN_EXISTING, CreateFileFlags.FILE_ATTRIBUTE_NORMAL, SafeObjectHandle.Null);
HANDLE handle;
fixed (char* pPath = &path[0])
{
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);
}

if (!handle.IsInvalid)
if (!handle.Equals(Constants.INVALID_HANDLE_VALUE))
{
var fileHandle = new SafeFileHandle(handle.DangerousGetHandle(), ownsHandle: true);
handle.SetHandleAsInvalid();
var fileHandle = new SafeFileHandle(handle, ownsHandle: true);
stream = new FileStream(fileHandle, System.IO.FileAccess.Read);
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/NerdBank.GitVersioning/NativeMethods.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "https://aka.ms/CsWin32.schema.json"
}
2 changes: 2 additions & 0 deletions src/NerdBank.GitVersioning/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CreateFile
INVALID_HANDLE_VALUE
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<PackageReference Include="DotNetMDDocs" Version="0.111.0" PrivateAssets="all" Condition=" '$(GenerateMarkdownApiDocs)' == 'true' " />
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0096" PrivateAssets="none" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.478-beta" PrivateAssets="all" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
<PackageReference Include="Validation" Version="2.5.5-beta" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.4.173-alpha" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="PInvoke.Kernel32" Version="0.7.104" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\**\*.cs" LinkBase="Shared" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ IMPORTANT: The 3.x release may produce a different version height than prior maj
<file src="$BaseOutputPath$net461\NerdBank.GitVersioning.dll" target="build\MSBuildFull\NerdBank.GitVersioning.dll" />
<file src="$BaseOutputPath$net461\Nerdbank.GitVersioning.Tasks.dll" target="build\MSBuildFull\Nerdbank.GitVersioning.Tasks.dll" />
<file src="$BaseOutputPath$net461\Newtonsoft.Json.dll" target="build\MSBuildFull\Newtonsoft.Json.dll" />
<file src="$BaseOutputPath$net461\PInvoke.Kernel32.dll" target="build\MSBuildFull\PInvoke.Kernel32.dll" />
<file src="$BaseOutputPath$net461\System.Buffers.dll" target="build\MSBuildFull\System.Buffers.dll" />
<file src="$BaseOutputPath$net461\System.Memory.dll" target="build\MSBuildFull\System.Memory.dll" />
<file src="$BaseOutputPath$net461\System.Numerics.Vectors.dll" target="build\MSBuildFull\System.Numerics.Vectors.dll" />
Expand All @@ -49,7 +48,6 @@ IMPORTANT: The 3.x release may produce a different version height than prior maj
<file src="$BaseOutputPath$netcoreapp2.1\System.Text.Json.dll" target="build\MSBuildCore\System.Text.Json.dll" />
<file src="$BaseOutputPath$netcoreapp2.1\Validation.dll" target="build\MSBuildCore\Validation.dll" />
<file src="$BaseOutputPath$netcoreapp2.1\System.Runtime.CompilerServices.Unsafe.dll" target="build\MSBuildCore\System.Runtime.CompilerServices.Unsafe.dll" />
<file src="$BaseOutputPath$netcoreapp2.1\PInvoke.Kernel32.dll" target="build\MSBuildCore\PInvoke.Kernel32.dll" />

<file src="build\Nerdbank.GitVersioning.targets" target="build\Nerdbank.GitVersioning$LKGSuffix$.targets" />
<file src="build\Nerdbank.GitVersioning.Common.targets" target="build\Nerdbank.GitVersioning.Common.targets" />
Expand Down
5 changes: 3 additions & 2 deletions src/Nerdbank.GitVersioning.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

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

0 comments on commit a0fb5ac

Please sign in to comment.