Setting file version for a codeDOM file

2019-04-13 14:30发布

I'm looking for ANY means of setting the file version for an exe file generated using codeDOM. Mine always comes out as 0.0.0.0. Programatically would obviously be preferred, but at this point anything would be better than nothing.

1条回答
爷的心禁止访问
2楼-- · 2019-04-13 15:10

The version of the compiled assembly is controlled by the AssemblyFileVersion attribute. You just need to make sure this is included as part of your CodeDom tree when you compile.

You can set this by adding the attribute into the CodeCompileUnit AssemblyCustomAttributes member.

    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);
查看更多
登录 后发表回答