c# - 您可以在 .NET Standard 库之间共享版本信息吗?
问题描述
在典型的 .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 项目中,版本信息似乎直接烘焙到该<PropertyGroup>
部分下的项目文件中,因此我不确定我们如何才能实现相同的功能。
.NET Standard 有什么支持这一点的吗?
解决方案
是的,你可以;o)
将名为Properties的文件夹添加到每个项目根目录,并将链接添加到AssemblyInfo_Shared.cs。
之后,您必须在每个 .Net Standard/Core 项目配置中进行设置
<PropertyGroup>
...
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
推荐阅读
- ios - SwiftUI 程序化导航。如何使用绑定
当方法需要绑定时 ? - python - 使用 beautifulsoup 提取了错误的文本
- html - 如何在移动网络电话上删除我的 wordpress 主题的右侧空白?
- regex - 如何在 Google 分析报告中删除 URL 末尾的双斜杠
- python - Pygame精灵不断重绘到屏幕上并且不动
- angular - Angular CKEditor 图像上传
- tensorflow - 不支持 Tensorflow XLA Conv1D 运算符?
- django - Django:当有人发表评论时如何填充其他模型字段
- javascript - 如何合并不同的节点模块并从中制作不同的捆绑包?
- r - 使用条件正则表达式分隔列