【问题标题】:How to embed AssemblyFileVersion in resource/constant/string/other?如何在资源/常量/字符串/其他中嵌入 AssemblyFileVersion?
【发布时间】:2012-10-17 12:03:17
【问题描述】:

我一直在使用代码similar to this 阅读AssemblyFileVersion,但由于安全限制,我不能再使用Assembly.GetExecutingAssembly(或Assembly 命名空间中的任何方法)。

(顺便说一句 - 这是 SharePoint Online 施加的安全限制,它会在上传时对您的程序集进行一些询问,如果您使用框架的某些禁止部分,则会拒绝它)

那么还有其他获取程序集文件版本的方法吗?

我猜不是,那么有什么方法可以将 AssemblyInfo.cs 中的 AssemblyFileVersion 属性放入资源文件或常量之类的东西中,这样就可以在运行时访问它而不使用 GetExectingAssembly?

【问题讨论】:

  • 可以我想将 AssemblyInfo.cs 设置为“复制到输出”,然后手动解析它。或者可能作为构建过程的一部分写入文件?

标签: c# .net visual-studio msbuild


【解决方案1】:

这就是我想出的。丑陋但符合目标(定义 AssemblyFileVersion 的单一位置),没有任何 MSBuild 技巧将 AssemblyFileVersion 写入资源文件。

文件:AssemblyInfo.cs

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MyProject")]
...
[assembly: AssemblyFileVersion(MyProject.AssemblyInfo.AssemblyFileVersion)]

namespace MyProject
{
    static internal class AssemblyInfo
    {
        /// <summary>
        /// The AssemblyFileVersion of this web part
        /// </summary>
        internal const string AssemblyFileVersion = "1.0.3.0";
    }
}

【讨论】:

    猜你喜欢
    • 2010-10-01
    • 2010-09-07
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    相关资源
    最近更新 更多