![](/img/trans.png)
[英]How to avoid repeated constant string in .NET AssemblyVersion and AssemblyFileVersion
[英]How to embed AssemblyFileVersion in resource/constant/string/other?
我一直在使用与此类似的代码阅读AssemblyFileVersion
,但由于安全限制,不能再使用Assembly.GetExecutingAssembly
(或Assembly命名空间中的任何方法)。
(顺便说一句 - 这是SharePoint Online强加的安全限制,它在上传时对您的程序集进行一些查询,如果您使用框架的某些禁止部分则拒绝它)
那么有没有其他方法来获取程序集文件版本?
我猜不是,有没有什么方法可以将AssemblyInfo.cs中的AssemblyFileVersion属性放入类似资源文件或常量的东西中,这样就可以在运行时访问它而不使用GetExectingAssembly?
这就是我想出来的。 很难但很满足目标(定义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";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.