博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Roslyn 使用 Directory.Build.props 管理多个项目配置
阅读量:4036 次
发布时间:2019-05-24

本文共 1873 字,大约阅读时间需要 6 分钟。

在一些大项目需要很多独立的仓库来做,每个仓库之间都会有很多相同的配置,本文告诉大家如何通过 Directory.Build.props 管理多个项目配置

在我的 MVVM 框架需要三个不同的库,一个是 Framework 另外两个是 WPF 和 UWP 这三个库有很多重复的配置,如版本号和作者信息。

在之前,我每次发布的时候,我都需要修改三个不同的仓库的版本号,将几个版本号升级到最新,但是这个方法如大家所见,效率是很低的。

在我的另外的博客 Roslyn 通过 Nuget 管理公司配置 和 Roslyn 通过 nuget 统一管理信息 介绍了统一管理配置的优点。

但是很显然,我暂时无法使用 nuget 的方法统一几个仓库的配置,我需要一个新的方式。

在看到我之前的博客 Roslyn 使用 Directory.Build.props 文件定义编译 可以知道,通过 Directory.Build.props 文件可以修改配置。

于是本渣就使用这个方法统一配置,我在项目的最外面添加了 Directory.Build.props 文件

我创建了 Build 文件夹,这个文件夹里面就放一个文件,这个文件就是管理版本号

Build\Version.props
2.1.156

现在的问题是如何让 Framework 三个不同的仓库引用这个文件,使用这个文件的版本号

通过 Directory.Build.props 添加下面的代码就可以让 Framework 项目找到版本号

这样就可以导入版本号文件,也就是可以让 Framework 等项目引用这个文件

除了版本号也有很多的信息可以通过这个方式配置,如设置作者信息,作者的信息是属性需要使用下面代码

lindexi

除了作者还有很多相同的信息,如仓库的路径,下面我就直接将所有可以用到的属性写出来,这样大家可以复制下面的代码到自己的 Directory.Build.props 通过修改信息定义自己的配置

$(MSBuildThisFileDirectory)bin\$(Configuration)
$(OutputPath)
true
lindexi
true
https://github.com/lindexi/UWP/tree/master/uwp/src/Framework
https://github.com/lindexi/UWP/tree/master/uwp/src/Framework
MIT
https://github.com/lindexi/UWP/blob/master/LICENSE
WPF;MVVM;UWP

上面的代码的 $(MSBuildThisFileDirectory) 就是替换文件所在的文件夹路径,更多请看 项目文件中的已知属性(知道了这些,就不会随便在 csproj 中写死常量啦) - walterlv:https://blog.walterlv.com/post/known-properties-in-csproj.html

更多关于 Roslyn 请看 手把手教你写 Roslyn 修改编译 :  https://blog.lindexi.com/post/roslyn.html

参见:Roslyn 入门 - CSDN博客

转载地址:http://dfudi.baihongyu.com/

你可能感兴趣的文章
[LeetCode By Python] 2 Add Two Number
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[LeetCode By Python]9. Palindrome Number
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]108. Convert Sorted Array to Binary Search Tree
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
python jieba分词模块的基本用法
查看>>
[CCF BY C++]2017.12 最小差值
查看>>
[CCF BY C++]2017-12 游戏
查看>>
如何打开ipynb文件
查看>>
[Leetcode BY python ]190. Reverse Bits
查看>>
面试---刷牛客算法题
查看>>