MSBuild Reference tag to pull over the ijwhost.dll if it can detect the assembly is a C++/CLI assembly
See original GitHub issueI want to make a c++/cli wrapper to use c++ in c# and then pack it into a NuGet package.
I tried it with a c# project in the solution first by project referencing
the c++/cli project. -> (this worked)
Then I tried packing it into a NuGet (which I am really new to) but when adding the NuGet and executing the project I got the BadImageFormatException
.
Later I found out that this exception is also thrown by just simply referencing the c++/cli project as a assembly.
Summary:
My main issue is that I can’t load my c++/cli wrapper in form of a dll,
but only as a project reference
.
Upon loading it as an assembly I get the BadImageFormatException
. (As already mentioned above)
For more info to my main issue see dotnet/runtime#57642 or look at the demo of my project https://github.com/wwelias/demo_core.git.
Under the first issue I created @AaronRobinsonMSFT said the following things (I hope I understood them correctly and ain’t saying wrong stuff now):
-
Problem with how SDK copies dependencies upon doing a
Reference
-
Probably has to do with the
ijwhost.dll
missing I tried moving theijwhost.dll
to various locations e. g. the folder of thedemo_cs.exe
but the outcome was the same. -
As a potential fix he recommended to include a MSBuild
Reference
tag to pull over theijwhost.dll
if it can detect that the assembly is a C++/CLI assembly and to create a new issue here.
Maybe anyone can help me?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Thanks for the snippets, that’s also how I currently workaround the problem. Just wanted to make sure I hadn’t missed a better solution.
@jnyrup this is the
.tragets
-File I used:<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)Ijwhost.dll">
<Link>Ijwhost.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
It basically copies the
Ijwhost.dll
into the OutputDirectory which is exactly what we need. But don’t forget to add the theIjwhost.dll
to your files in the.nuspec
because otherwise it won’t be included in the.nupkg
and it has nothing to copy. <file src="build\Ijwhost.dll" target="build\Ijwhost.dll" /><?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
...
</metadata>
<files>
<file src="build\Ijwhost.dll" target="build\Ijwhost.dll" />
...
</files>
</package>
Hope this kind of inserting code is okay to look at… don’t know how I can make it better bcs I am new to github. And I hope this helped.