如何将自定义属性添加到 CodeDOM 输出
How Do I Add Custom Properties To CodeDOM Output
我正在尝试向 CodeDOM 输出添加自定义属性,例如文件版本、作者等。我不确定如何操作。
对于文件版本,您必须使用 AssemblyFileVersion
属性。
参见 example.
CodeCompileUnit unit = CreateMyUnit();
var attribute = new CodeAttributeDeclaration(
new CodeTypeReference(typeof(AssemblyFileVersionAttribute)));
attribute.Arguments.Add(
new CodeAttributeArgument(
new CodePrimitiveExpression("1.1.1.1")));
unit.AssemblyCustomAttributes.Add(attribute);
至于作者,你可能会做类似的事情。见 MSDN assembly attribute.
编辑:
您需要添加引用。
using System.CodeDom;
using System.CodeDom.Compiler;
我正在尝试向 CodeDOM 输出添加自定义属性,例如文件版本、作者等。我不确定如何操作。
对于文件版本,您必须使用 AssemblyFileVersion
属性。
参见 example.
CodeCompileUnit unit = CreateMyUnit();
var attribute = new CodeAttributeDeclaration(
new CodeTypeReference(typeof(AssemblyFileVersionAttribute)));
attribute.Arguments.Add(
new CodeAttributeArgument(
new CodePrimitiveExpression("1.1.1.1")));
unit.AssemblyCustomAttributes.Add(attribute);
至于作者,你可能会做类似的事情。见 MSDN assembly attribute.
编辑:
您需要添加引用。
using System.CodeDom;
using System.CodeDom.Compiler;