InjectModuleInitializer.exe for .NET 4.5 or greater
Currently the InjectModuleInitializer.exe needs .NET 3.5 to run. Could you create a version that targets the .NET framework 4.5 or greater?
Creating a .config in the same folder as the executable with a supportedRuntime entry should work.
We have the same problem - our builds are failing on Jenkins because .NET 3.5 isn't installed on the build agents. This also makes it a little bit difficult to create the .config file, as Nuget is managing the packages.
For anyone who comes hunting for a solution to this, I have a workaround. The symptom is that your build will fail with something like:
error MSB3073: The command ""somepath\.nuget\packages\injectmoduleinitializer\2.0.3\tools\net35\InjectModuleInitializer.exe" /k:".StrongNameKey.snk" "MyDLL.dll"" exited with code -2146232576
The solution is to add a .config file to InjectModuleInitializer.exe as part of the build process, so whenever Nuget fetches a new version we add the config file alongside it. To do this:
- Create a file called InjectModuleInitializer.exe.config with this content:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
- Add this to your project to modify
<PackageReference>forInjectModuleInitializer:
<ItemGroup>
<PackageReference Include="InjectModuleInitializer" Version="2.0.3" GeneratePathProperty="true">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<!-- Make InjectModuleInitializer compatible with .NET 4.x -->
<Target Name="FixInjectModuleInitializer" BeforeTargets="InjectModuleInitializer">
<Copy SourceFiles="$(ProjectDir)\InjectModuleInitializer.exe.config"
DestinationFolder="$(PkgInjectModuleInitializer)\tools\net35" />
</Target>
Note the GeneratePathProperty="true" that's been added.
Hey presto, the config file will be copied alongside InjectModuleInitializer.exe just before it is used and it will run under .NET 4.