Skip to content

Commit 9e74f1e

Browse files
committed
Include BCL assemblies required for VS 2017 build tools
Several assemblies are required by this msbuild task but are not included in MSBuild 2017. Adding the assemblies to the package alone is not enough, since binding redirects are also missing in msbuild.exe.config. We make up for this with a custom assembly resolver. Fixes #589
1 parent 8126d95 commit 9e74f1e

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

azure-pipelines.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ stages:
5858
displayName: Configure git commit author for testing
5959
6060
- task: UseDotNet@2
61-
displayName: Install .NET Core SDK 5.0.100
61+
displayName: Install .NET Core SDK 5.0.202
6262
inputs:
6363
packageType: sdk
64-
version: 5.0.100
64+
version: 5.0.202
6565

6666
- task: UseDotNet@2
6767
displayName: Install .NET Core 3.1
@@ -306,10 +306,10 @@ stages:
306306
packageType: sdk
307307
version: 3.1.100
308308
- task: UseDotNet@2
309-
displayName: Install .NET Core SDK 5.0.100
309+
displayName: Install .NET Core SDK 5.0.202
310310
inputs:
311311
packageType: sdk
312-
version: 5.0.100
312+
version: 5.0.202
313313
- script: dotnet --info
314314
displayName: Show dotnet SDK info
315315
- bash: |

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "5.0.100"
3+
"version": "5.0.202"
44
}
55
}

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)..\obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
55
<OutputPath>$(MSBuildThisFileDirectory)..\bin\$(MSBuildProjectName)\$(Configuration)\</OutputPath>
66
<DocumentationRootFolder>$(MSBuildThisFileDirectory)..\wiki\api</DocumentationRootFolder>
7-
<LangVersion>8.0</LangVersion>
7+
<LangVersion>9.0</LangVersion>
88

99
<SignAssembly>true</SignAssembly>
1010
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)strongname.snk</AssemblyOriginatorKeyFile>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#if NETFRAMEWORK
2+
3+
using System;
4+
using System.IO;
5+
using System.Reflection;
6+
using System.Runtime.CompilerServices;
7+
8+
namespace System.Runtime.CompilerServices
9+
{
10+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
11+
public sealed class ModuleInitializerAttribute : Attribute { }
12+
}
13+
14+
namespace Nerdbank.GitVersioning.Tasks
15+
{
16+
internal static class AssemblyLoader
17+
{
18+
[ModuleInitializer]
19+
internal static void LoaderInitializer()
20+
{
21+
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
22+
}
23+
24+
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
25+
{
26+
try
27+
{
28+
var required = new AssemblyName(args.Name);
29+
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), required.Name + ".dll");
30+
if (File.Exists(path))
31+
{
32+
AssemblyName actual = AssemblyName.GetAssemblyName(path);
33+
if (actual.Version >= required.Version)
34+
{
35+
return Assembly.LoadFile(path);
36+
}
37+
}
38+
}
39+
catch
40+
{
41+
}
42+
43+
return null;
44+
}
45+
}
46+
}
47+
48+
#endif

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ 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" />
27+
<file src="$BaseOutputPath$net461\System.Buffers.dll" target="build\MSBuildFull\System.Buffers.dll" />
28+
<file src="$BaseOutputPath$net461\System.Memory.dll" target="build\MSBuildFull\System.Memory.dll" />
29+
<file src="$BaseOutputPath$net461\System.Numerics.Vectors.dll" target="build\MSBuildFull\System.Numerics.Vectors.dll" />
30+
<file src="$BaseOutputPath$net461\System.Runtime.CompilerServices.Unsafe.dll" target="build\MSBuildFull\System.Runtime.CompilerServices.Unsafe.dll" />
2631
<file src="$BaseOutputPath$net461\System.Text.Json.dll" target="build\MSBuildFull\System.Text.Json.dll" />
2732
<file src="$BaseOutputPath$net461\Validation.dll" target="build\MSBuildFull\Validation.dll" />
28-
<file src="$BaseOutputPath$net461\System.Runtime.CompilerServices.Unsafe.dll" target="build\MSBuildFull\System.Runtime.CompilerServices.Unsafe.dll" />
29-
<file src="$BaseOutputPath$net461\PInvoke.Kernel32.dll" target="build\MSBuildFull\PInvoke.Kernel32.dll" />
3033
<file src="$LibGit2SharpNativeBinaries$runtimes\**" target="build\runtimes\" />
3134

3235
<!-- Additional copies to work around DllNotFoundException on Mono (https://github.com/dotnet/Nerdbank.GitVersioning/issues/222) -->

0 commit comments

Comments
 (0)