作者:孤独中残存的幸福_627 | 来源:互联网 | 2022-12-06 10:01
在典型的.NET应用程序中,产品和版本信息存储在AssemblyInfo.cs
"属性"文件夹下的文件中,如此...
DLL Project
- Properties Folder
- AssemblyInfo.cs
在我们的例子中,我们有一个解决方案,我们需要保持版本信息在11个DLL之间同步.
为此,我们首先从每个项目的AssemblyInfo.cs
文件中删除任何共享值,只留下特定于该特定项目的那些值.
然后,我们将所有共享值放在第二个文件中,该文件AssemblyInfo_Shared.cs
存储在兄弟文件夹中,并存储到项目的文件夹中.然后我们通过一个链接将该文件添加到每个项目的"属性"文件夹中(当你添加它时,这是按钮上的小'向下'箭头.)
通过这样做,所有相关的DLL共享相同的版本信息,同时仍保留特定于程序集的属性.当我们编辑单个文件并且所有11个DLL的版本一次更新时,它使一组版本化的DLL同步变得轻而易举.
这是它的样子......
Common Folder
- AssemblyInfo_Shared.cs (Actual)
DLL Project A
- Properties Folder
- AssemblyInfo.cs // Only values specific to A
- AssemblyInfo_Shared.cs (Link)
DLL Project B
- Properties Folder
- AssemblyInfo.cs // Only values specific to B
- AssemblyInfo_Shared.cs (Link)
项目A中的AssemblyInfo.cs的内容如下所示......
using System.Reflection;
[assembly: AssemblyTitle("SomeApp.LibA")]
[assembly: AssemblyDescription("This is the code for A")]
这是项目B的
using System.Reflection;
[assembly: AssemblyTitle("SomeApp.LibB")]
[assembly: AssemblyDescription("This is the code for Project B")]
这是共享的......
using System;
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
[assembly: AssemblyProduct("SomeApp")]
[assembly: AssemblyVersion("1.4.3.0")]
[assembly: AssemblyFileVersion("1.4.3.0")]
[assembly: AssemblyCompany("MyCo")]
[assembly: AssemblyCopyright("Copyright (c) 2010-2018, MyCo")]
[assembly: ComVisible(false)]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
有了上述内容,两个DLL共享相同的版本信息,因为公共文件在构建时与项目特定文件"合并".希望这是有道理的.
但是,在.NET Standard项目中,看起来版本信息直接出现在该
部分下的Project文件中,因此我不确定如何实现相同的功能.
.NET Standard有什么支持这个吗?
1> Sir Rufo..:
是的,你可以; o)
向每个项目根目录添加一个名为Properties的文件夹,并将链接添加到AssemblyInfo_Shared.cs。
之后,您必须在每个.Net Standard / Core项目配置中进行设置
...
false
您可以在https://github.com/SirRufo/SharedVersionTest中找到完整的解决方案