admin管理员组文章数量:1389807
Following is the content of the auto-generated <ProjectName>.GlobalUsings.g.cs
file when a Console Application or a Class Library project is created -
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
How can I modify the template for this file to add a few more namespaces?
Note: I know additional namespaces can be added through the project file, but I want to modify the default template for the auto-generated file.
Following is the content of the auto-generated <ProjectName>.GlobalUsings.g.cs
file when a Console Application or a Class Library project is created -
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
How can I modify the template for this file to add a few more namespaces?
Note: I know additional namespaces can be added through the project file, but I want to modify the default template for the auto-generated file.
Share Improve this question asked Mar 13 at 20:42 atiyaratiyar 8,3277 gold badges40 silver badges82 bronze badges 2 |1 Answer
Reset to default 3Per Selvin's comment what you probably DON'T want to modify is:
dotnet\sdk\VERSION\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.CSharp.props
which serves as the base source for the auto-generated usings file:
<!-- Implicit imports -->
<ItemGroup Condition="'$(ImplicitUsings)' == 'true' Or '$(ImplicitUsings)' == 'enable'">
<Using Include="System" />
<Using Include="System.Collections.Generic" />
<Using Include="System.IO" />
<Using Include="System.Linq" />
<Using Include="System.Net.Http" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'"/>
<Using Include="System.Threading" />
<Using Include="System.Threading.Tasks" />
</ItemGroup>
However, your code will have issues when you
- Upgrade the SDK on your machine
- Try to build it on another machine where you haven't manually modified the SDK files
The recommended alternative is a "specifically named" GlobalUsings.cs
file that you just copy-paste to new projects where you put those extra usings:
global using System.Diagnostics;
本文标签: cHow do I modify the template for the autogenerated global using fileStack Overflow
版权声明:本文标题:c# - How do I modify the template for the auto-generated global using file? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744686121a2619709.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.props
file(in sdk folder) and modify it but this doesn't make sense... You can always useDirectory.Build.props
to add some props to every project in solution – Selvin Commented Mar 13 at 21:01