1

We're building a C# wrapper for a C library in embedded Linux, and we want to install it into the GAC of the target system.

To do that, I've used sn to create a keypair and mcs to compile the code:

sn -k keypair.snk
mcs /target:library -keyfile:keypair.snk -out:MyLib.dll src/*.cs

Now, once that's built, I use gacutil to inject it into the GAC with:

gacutil /i -gacdir /path/to/gac MyLib.dll

What I end up with is the correct file structure but the version number is set to 0.0.0.0:

.../usr/lib/mono/gac/MyLib
.../usr/lib/mono/gac/MyLib/0.0.0.0__3141592653589fff
.../usr/lib/mono/gac/MyLib/0.0.0.0__3141592653589fff/MyLib.dll

I want the version of the wrapper to match that of the underlying C code being used so my question is (hopefully) a simple one. Where is that current version coming from, and how do I get it to be 3.14.15.9 (for example)?

4

1 回答 1

3

添加调用AssemblyVersion到 C# 源的程序集级属性。这通常添加在一个名为 的文件中AssemblyInfo.cs

注意:这是自动生成的项目文件的剪切/粘贴,我更新了 AssemblyVersion 属性,您只需包含您希望 CIL 程序集包含的属性

using System.Reflection;
//using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes. 
// Change them to the values specific to your project.

[assembly: AssemblyTitle("Sushi.Task.Lib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SushiHangover")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("SushiHangover - 2016")]
[assembly: AssemblyTrademark("SushiHangover")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("3.14.15.9")]

// The following attributes are used to specify the signing key for the assembly, 
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

将该源文件添加到您正在编译的其他文件中。

安装它:

>gacutil /i Sushi.Task.Lib.dll

并检索详细信息:

>gacutil /l |grep -i sushi

Sushi.Task.Lib, Version=3.14.15.9, Culture=neutral,....

文件系统:

ls -Rl /Frameworks/Mono.framework/gac | grep -i sushi
drwxr-xr-x   3 root  admin  102 Jun  8 20:25 Sushi.Task.Lib
/Frameworks/Mono.framework/gac/Sushi.Task.Lib:
/Frameworks/Mono.framework/gac/Sushi.Task.Lib/3.14.15.9__629e3fd32ae394a7:.....
于 2016-06-09T03:36:02.757 回答