Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InjectModuleInitializer.exe for .NET 4.5 or greater #18

Open
GR-C opened this issue May 29, 2019 · 3 comments
Open

InjectModuleInitializer.exe for .NET 4.5 or greater #18

GR-C opened this issue May 29, 2019 · 3 comments

Comments

@GR-C
Copy link

GR-C commented May 29, 2019

Currently the InjectModuleInitializer.exe needs .NET 3.5 to run. Could you create a version that targets the .NET framework 4.5 or greater?

@mford1
Copy link

mford1 commented Jul 8, 2019

Creating a .config in the same folder as the executable with a supportedRuntime entry should work.

@stevebaxter
Copy link

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.

@stevebaxter
Copy link

stevebaxter commented Oct 14, 2021

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:

  1. 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>
  1. Add this to your project to modify <PackageReference> for InjectModuleInitializer:
  <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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants