开发者

Injecting resources into the manifest of a .NET assembly post-build

开发者 https://www.devze.com 2023-01-15 17:08 出处:网络
Is there a way for me to insert a resource into the manifest of another assembly? I\'ve been experimenting with MSBuild and ILMerge but apparently a resouce assembly created by the Assembly Linker ca

Is there a way for me to insert a resource into the manifest of another assembly?

I've been experimenting with MSBuild and ILMerge but apparently a resouce assembly created by the Assembly Linker can not be merged wtih ILMerge, looks like ILMerge cant do a resource only merge.

al /o开发者_高级运维ut:Resources.dll /embed:Test.txt,Resources.Test

ilmerge just yields an error

ILMerge.Merge: Could not load assembly from the location 'Resources.dll'


Okay, I actually had the answer, my ILMerge version must have been buggy...

I took the C# class template .cs file and compiled that in the simplest way

> csc /target:library Class1.cs

I then use the Assembly Linker part of the Windows SDK to create a trivial resource assembly (quicker)

> al /out:TextFile1.dll /embed:TextFile1.txt

This last part failed with a stupid null reference exception, last time I tried this. But just now it worked like a charm.

> ilmerge /out:Merged.dll Class1.dll TextFile1.dll

You can verify the result using ildasm

> ildasm /text Merged.dll
...
.mresource public TextFile1.txt
{
  // Offset: 0x00000000 Length: 0x00000003
}

...and that's it!

I use this to inject stuff into assemblies post-build as part of the build process. e.g. SVN log information. So that I can track a binary to a specific revision and person.

0

精彩评论

暂无评论...
验证码 换一张
取 消