.net 核心项目中的 SharedAssemblyInfo 等价物? [英] SharedAssemblyInfo equivalent in .net core projects?
问题描述
当我希望一个解决方案中的多个项目共享相同的程序集信息(主要是 AssemblyVersion)时,我曾经使用这里解释的技术:https://blogs.msdn.microsoft.com/jjameson/2009/04/03/shared-assembly-info-in-visual-studio-projects/
When I wanted multiple projects in a solution to share the same assembly informations (mainly AssemblyVersion), I used to use the tecnique explained here: https://blogs.msdn.microsoft.com/jjameson/2009/04/03/shared-assembly-info-in-visual-studio-projects/
现在我们正在研究 .net core 和 asp.net core 项目的解决方案,我们希望所有项目共享相同的 AssemblyVersion,但现在每个项目的版本都存储在它的 .csproj 文件中(我们使用的是 vs2017)
Now we're working on a solution of .net core and asp.net core projects and we want all projects to share the same AssemblyVersion, but now each project's version is stored inside it's .csproj file (we're using vs2017)
我尝试使用
生成信息,但新文件是在构建时创建的
I tried with generating info with <GenerateAssemblyProductAttribute>true</GenerateAssemblyProductAttribute>
but the new file is created at build-time
有没有办法像旧的"SharedAssemblyInfo.cs 方式一样集中这些信息?
Is there a way to centralize this information like in the "old" SharedAssemblyInfo.cs way?
推荐答案
您可以在要为其设置默认属性的所有 .csproj 文件之上添加一个 Directory.Build.props
文件.这个 .props
文件将自动导入到它下面的所有 .csproj
文件中.您可以在其中设置常用属性:
You can add a Directory.Build.props
file above all the .csproj files that you want to default properties for. This .props
file will automatically be imported in all the .csproj
files below it. You can set common properties in it:
<Project>
<PropertyGroup>
<Company>Erhardt Enterprises</Company>
<Copyright>Erhardt Enterprises ©</Copyright>
</PropertyGroup>
</Project>
并且这些 MSBuild 属性将应用于其下的所有 .csproj
文件.因此,当生成程序集属性时,这些值将在所有项目中使用.
And these MSBuild properties will apply to all the .csproj
files under it. So when the assembly attributes are generated, these values will be used across all projects.
这篇关于.net 核心项目中的 SharedAssemblyInfo 等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!