Rya*_*yan 3 .net c# msbuild visual-studio
我一直在阅读与此类似的AssemblyFileVersion使用代码,但Assembly.GetExecutingAssembly由于安全限制,不能再使用(或程序集命名空间中的任何方法).
(顺便说一句 - 这是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";
}
}
Run Code Online (Sandbox Code Playgroud)