|
15 | 15 |
|
16 | 16 | public class GetBuildVersion : Task |
17 | 17 | { |
18 | | -#if !NET45 |
19 | 18 | /// <summary> |
20 | 19 | /// An AppDomain-wide variable used on |
21 | 20 | /// </summary> |
22 | 21 | private static bool libgit2PathInitialized; |
23 | | -#endif |
24 | 22 |
|
25 | 23 | /// <summary> |
26 | 24 | /// Initializes a new instance of the <see cref="GetBuildVersion"/> class. |
@@ -52,13 +50,14 @@ public GetBuildVersion() |
52 | 50 | public string GitRepoRoot { get; set; } |
53 | 51 |
|
54 | 52 | /// <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. |
56 | 54 | /// </summary> |
57 | 55 | /// <remarks> |
58 | 56 | /// This is particularly useful in .NET Core where discovering one's own assembly path |
59 | 57 | /// is not allowed before .NETStandard 2.0. |
60 | 58 | /// </remarks> |
61 | | - public string TaskAssemblyPath { get; set; } |
| 59 | + [Required] |
| 60 | + public string TargetsPath { get; set; } |
62 | 61 |
|
63 | 62 | /// <summary> |
64 | 63 | /// Gets or sets a value indicating whether the project is building |
@@ -163,10 +162,7 @@ public override bool Execute() |
163 | 162 | { |
164 | 163 | try |
165 | 164 | { |
166 | | - if (!this.HelpFindLibGit2NativeBinaries()) |
167 | | - { |
168 | | - return false; |
169 | | - } |
| 165 | + this.HelpFindLibGit2NativeBinaries(); |
170 | 166 |
|
171 | 167 | var cloudBuild = CloudBuild.Active; |
172 | 168 | var oracle = VersionOracle.Create(Directory.GetCurrentDirectory(), this.GitRepoRoot, cloudBuild); |
@@ -213,24 +209,25 @@ public override bool Execute() |
213 | 209 | return true; |
214 | 210 | } |
215 | 211 |
|
216 | | - private bool HelpFindLibGit2NativeBinaries() |
| 212 | + private void HelpFindLibGit2NativeBinaries() |
217 | 213 | { |
218 | | -#if !NET45 |
219 | | - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !libgit2PathInitialized) |
| 214 | + if (!libgit2PathInitialized) |
220 | 215 | { |
221 | | - if (string.IsNullOrWhiteSpace(this.TaskAssemblyPath)) |
| 216 | + string nativeDllPath = null; |
| 217 | +#if !NET45 |
| 218 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 219 | +#endif |
222 | 220 | { |
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); |
225 | 227 | } |
226 | 228 |
|
227 | | - string nativeDllPath = Path.Combine(this.TaskAssemblyPath, "lib", "win32", IntPtr.Size == 4 ? "x86" : "x64"); |
228 | | - Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + Path.PathSeparator + nativeDllPath); |
229 | 229 | libgit2PathInitialized = true; |
230 | 230 | } |
231 | | -#endif |
232 | | - |
233 | | - return true; |
234 | 231 | } |
235 | 232 | } |
236 | 233 | } |
0 commit comments