6

Roslyn 禁止 sdk style csproj 默认引用 Compile 代码文件

 3 years ago
source link: https://lindexi.gitee.io/post/Roslyn-%E7%A6%81%E6%AD%A2-sdk-style-csproj-%E9%BB%98%E8%AE%A4%E5%BC%95%E7%94%A8-Compile-%E4%BB%A3%E7%A0%81%E6%96%87%E4%BB%B6.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Roslyn 禁止 sdk style csproj 默认引用 Compile 代码文件

默认在 SDK Style 的 csproj 文件将会引用所有的 .cs 文件到 Compile 项,如果是 WPF 项目还会添加 xaml 的引用。如果想要自己手动设置,让一些项不默认引用,需要添加属性 EnableDefaultCompileItems 告诉 msbuild 不要默认引用

禁止 .cs 文件作为 Compile 的默认引用方法

<PropertyGroup>
    <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

如果没有禁止,将会使用如下引用

<Compile Include="**\*.cs" />

禁止 xaml 文件作为 Page 的默认引用

<PropertyGroup>
    <EnableDefaultPageItems>false</EnableDefaultPageItems>
</PropertyGroup>

禁止创建默认特性

<PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

关于默认特性创建请看 解决从旧格式的 csproj 迁移到新格式的 csproj 格式 AssemblyInfo 文件值重复问题

禁止图片等作为 None 默认引用

<PropertyGroup>
    <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
</PropertyGroup>

禁止 App.xaml 作为 ApplicationDefinition 默认引用

<PropertyGroup>
    <EnableDefaultApplicationDefinition>false</EnableDefaultApplicationDefinition>
</PropertyGroup>

禁止所有默认引用

<PropertyGroup>
    <EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>

从以前的项目格式迁移到 VS2017 新项目格式

MSBuild properties for Microsoft.NET.Sdk - .NET


本文会经常更新,请阅读原文: https://blog.lindexi.com/post/Roslyn-%E7%A6%81%E6%AD%A2-sdk-style-csproj-%E9%BB%98%E8%AE%A4%E5%BC%95%E7%94%A8-Compile-%E4%BB%A3%E7%A0%81%E6%96%87%E4%BB%B6.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。

如果你想持续阅读我的最新博客,请点击 RSS 订阅,推荐使用RSS Stalker订阅博客,或者前往 CSDN 关注我的主页

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系

无盈利,不卖课,做纯粹的技术博客

以下是广告时间

推荐关注 Edi.Wang 的公众号
lindexi%2F201985113622445

欢迎进入 Eleven 老师组建的 .NET 社区
lindexi%2F20209121930471745.jpg

以上广告全是友情推广,无盈利


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK