创建强命名程序集时的版本0.0.0.0

时间:2016-06-09 02:46:22

标签: linux mono version sn

我们正在为嵌入式Linux中的C库构建C#包装器,我们希望将其安装到目标系统的GAC中。

为此,我使用sn创建了密钥对,并使用mcs来编译代码:

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

现在,一旦构建完成,我就会使用gacutil将其注入GAC:

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

我最终得到的是正确的文件结构,但版本号设置为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

我希望包装器的版本与正在使用的底层C代码的版本相匹配,所以我的问题(希望)是一个简单的问题。当前版本来自哪里,如何将其作为3.14.15.9(例如)?

1 个答案:

答案 0 :(得分: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:.....