Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在resource/constant/string/other中嵌入AssemblyFileVersion?_C#_.net_Visual Studio_Msbuild - Fatal编程技术网

C# 如何在resource/constant/string/other中嵌入AssemblyFileVersion?

C# 如何在resource/constant/string/other中嵌入AssemblyFileVersion?,c#,.net,visual-studio,msbuild,C#,.net,Visual Studio,Msbuild,我一直在使用代码阅读AssemblyFileVersion,但由于安全限制,无法再使用Assembly.getExecutionGassembly(或程序集命名空间中的任何方法) (顺便说一句——这是SharePoint Online施加的安全限制,它在上载时对程序集进行一些询问,如果您使用框架的某些禁止部分,则会拒绝该程序集) 那么,还有其他方法可以获取程序集文件版本吗 我猜不会,那么有没有办法将AssemblyInfo.cs中的AssemblyFileVersion属性放入资源文件或常量中,

我一直在使用代码阅读
AssemblyFileVersion
,但由于安全限制,无法再使用
Assembly.getExecutionGassembly
(或程序集命名空间中的任何方法)

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

那么,还有其他方法可以获取程序集文件版本吗


我猜不会,那么有没有办法将AssemblyInfo.cs中的AssemblyFileVersion属性放入资源文件或常量中,这样就可以在运行时访问它,而无需使用GetExecutingAssembly?

这就是我想到的。Fugly,但满足目标(定义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";
    }
}
//有关程序集的一般信息通过以下方式控制
//属性集。更改这些属性值以修改信息
//与程序集关联的。
[大会:大会标题(“我的项目”)]
...
[程序集:AssemblyFileVersion(MyProject.AssemblyInfo.AssemblyFileVersion)]
名称空间MyProject
{
静态内部类AssemblyInfo
{
/// 
///此web部件的AssemblyFileVersion
/// 
内部常量字符串AssemblyFileVersion=“1.0.3.0”;
}
}
我假设您可以将AssemblyInfo.cs设置为“复制到输出”,然后手动解析它。或者作为构建过程的一部分写入文件?