我正在使用 CSScriptLibrary 在运行时创建程序集。一切正常,但我生成的程序集没有所需的程序集信息。
如果我在代码字符串中包含程序集信息属性(在每个 C# 项目的 AssemblyInfo.cs 中找到),编译将失败并出现“重复属性错误”。
这是我创建程序集的代码:
try
{
compiledResultAssembly = CSScriptLibrary.CSScript.LoadCode(code, assemblyReferences.ToArray());
}
catch(Exception ex)
{ }
如何指定程序集版本以使“compiledResultAssembly”不在版本 0.0.0.0 中?
CSScriptLibrary 的版本是 3.11.1.0。
提前致谢
编辑 08.07.2019
我找到了解决方案。CSScriptLibrary 在某些时候注入了一个 AssemblyDescription 属性,这会导致“重复属性”错误。
要指定程序集版本信息,只需使用以下脚本代码设置:
using System.Reflection;
using System.Runtime.InteropServices;
// all your usings
[assembly: AssemblyVersion("1.2.3.4")]
[assembly: AssemblyFileVersion("1.2.3.4")]
namespace YourNamespace
{
// your code here
}
请注意,程序集属性必须是代码中的第一件事,不能放在其他任何地方。