Skip to content

Commit 9b2b980

Browse files
committed
Fix msbuild.exe on Windows
1 parent e984bdc commit 9b2b980

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/Nerdbank.GitVersioning.NuGet/build/Nerdbank.GitVersioning.targets

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
3333
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
3434

35-
<NerdbankGitVersioningTasksPath Condition=" '$(NerdbankGitVersioningTasksPath)' == '' ">$(MSBuildThisFileDirectory)</NerdbankGitVersioningTasksPath>
35+
<_NBGV_PlatformSuffix Condition=" '$(_NBGV_PlatformSuffix)' == '' and '$(MSBuildRuntimeType)' == 'Core' ">MSBuildCore/</_NBGV_PlatformSuffix>
36+
<_NBGV_PlatformSuffix Condition=" '$(_NBGV_PlatformSuffix)' == '' ">MSBuildFull/</_NBGV_PlatformSuffix>
37+
<NerdbankGitVersioningTasksPath Condition=" '$(NerdbankGitVersioningTasksPath)' == '' ">$(MSBuildThisFileDirectory)$(_NBGV_PlatformSuffix)</NerdbankGitVersioningTasksPath>
3638
</PropertyGroup>
3739

3840
<UsingTask AssemblyFile="$(NerdbankGitVersioningTasksPath)Nerdbank.GitVersioning.Tasks.dll" TaskName="Nerdbank.GitVersioning.Tasks.AssemblyVersionInfo"/>
@@ -52,7 +54,7 @@
5254
BuildMetadata="@(BuildMetadata)"
5355
DefaultPublicRelease="$(PublicRelease)"
5456
GitRepoRoot="$(GitRepoRoot)"
55-
TaskAssemblyPath="$(NerdbankGitVersioningTasksPath)">
57+
TargetsPath="$(MSBuildThisFileDirectory)">
5658

5759
<Output TaskParameter="Version" PropertyName="BuildVersion" />
5860
<Output TaskParameter="AssemblyInformationalVersion" PropertyName="AssemblyInformationalVersion" />

src/Nerdbank.GitVersioning.Tasks/GetBuildVersion.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515

1616
public class GetBuildVersion : Task
1717
{
18-
#if !NET45
1918
/// <summary>
2019
/// An AppDomain-wide variable used on
2120
/// </summary>
2221
private static bool libgit2PathInitialized;
23-
#endif
2422

2523
/// <summary>
2624
/// Initializes a new instance of the <see cref="GetBuildVersion"/> class.
@@ -52,13 +50,14 @@ public GetBuildVersion()
5250
public string GitRepoRoot { get; set; }
5351

5452
/// <summary>
55-
/// Gets or sets the path to the folder that contains this task's assembly.
53+
/// Gets or sets the path to the folder that contains the NB.GV .targets file.
5654
/// </summary>
5755
/// <remarks>
5856
/// This is particularly useful in .NET Core where discovering one's own assembly path
5957
/// is not allowed before .NETStandard 2.0.
6058
/// </remarks>
61-
public string TaskAssemblyPath { get; set; }
59+
[Required]
60+
public string TargetsPath { get; set; }
6261

6362
/// <summary>
6463
/// Gets or sets a value indicating whether the project is building
@@ -163,10 +162,7 @@ public override bool Execute()
163162
{
164163
try
165164
{
166-
if (!this.HelpFindLibGit2NativeBinaries())
167-
{
168-
return false;
169-
}
165+
this.HelpFindLibGit2NativeBinaries();
170166

171167
var cloudBuild = CloudBuild.Active;
172168
var oracle = VersionOracle.Create(Directory.GetCurrentDirectory(), this.GitRepoRoot, cloudBuild);
@@ -213,24 +209,25 @@ public override bool Execute()
213209
return true;
214210
}
215211

216-
private bool HelpFindLibGit2NativeBinaries()
212+
private void HelpFindLibGit2NativeBinaries()
217213
{
218-
#if !NET45
219-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !libgit2PathInitialized)
214+
if (!libgit2PathInitialized)
220215
{
221-
if (string.IsNullOrWhiteSpace(this.TaskAssemblyPath))
216+
string nativeDllPath = null;
217+
#if !NET45
218+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
219+
#endif
222220
{
223-
this.Log.LogError("The TaskAssemblyPath parameter is required on .NET Core running on Windows.");
224-
return false;
221+
nativeDllPath = Path.Combine(this.TargetsPath, "lib", "win32", IntPtr.Size == 4 ? "x86" : "x64");
222+
}
223+
224+
if (nativeDllPath != null)
225+
{
226+
Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + Path.PathSeparator + nativeDllPath);
225227
}
226228

227-
string nativeDllPath = Path.Combine(this.TaskAssemblyPath, "lib", "win32", IntPtr.Size == 4 ? "x86" : "x64");
228-
Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + Path.PathSeparator + nativeDllPath);
229229
libgit2PathInitialized = true;
230230
}
231-
#endif
232-
233-
return true;
234231
}
235232
}
236233
}

0 commit comments

Comments
 (0)