简体   繁体   English

在VS中一次在多个代码文件中插入多个文本行

[英]Insert multiple text lines in multiple code files at once in VS

I need to know if there is a faster way than manually copy-pasting 4 new libraries in every code file that I have.我需要知道是否有比在我拥有的每个代码文件中手动复制粘贴 4 个新库更快的方法。 After a major refactoring and addition of new libraries, I need to include these in every code file:在对新库进行重大重构和添加之后,我需要在每个代码文件中包含这些:

using GameServerCore.Enums;
using GameServerCore.Scripting.CSharp;
using System.Numerics;
using GameServerLib.GameObjects.AttackableUnits;

I cant use Replace All because I cant replace anything to fit those, and manually copy-pasting them will take me ages because there are hundreds of.cs files.我不能使用Replace All ,因为我无法替换任何东西来适应它们,并且手动复制粘贴它们会花费我很长时间,因为有数百个 .cs 文件。

Using Visual Studio 2022, all script files are written in C#使用Visual Studio 2022,所有脚本文件都写在C#

Starting with C# 10 you can use global usings:从 C# 10 开始,您可以使用全局使用:

global using GameServerCore.Enums;
global using GameServerCore.Scripting.CSharp;
global using System.Numerics;
global using GameServerLib.GameObjects.AttackableUnits;

Add these global usings in one file in your project, eg "GlobalUsings.cs" and they will be active in all the *.cs files.在项目的一个文件中添加这些全局使用,例如“GlobalUsings.cs”,它们将在所有 *.cs 文件中处于活动状态。

The docs for using directive say: 使用指令的文档说:

The global modifier has the same effect as adding the same using directive to every source file in your project.全局修饰符与将相同的 using 指令添加到项目中的每个源文件具有相同的效果。 This modifier was introduced in C# 10.此修饰符是在 C# 10 中引入的。

According to Visual Studio 2022 version 17.3 Release Notes :根据Visual Studio 2022 版本 17.3 发行说明

We now surface an icon at the top of your file to let you know if Global Usings are active in your file and if you click on the icon, it will show you what those Global Usings are.我们现在在您的文件顶部显示一个图标,让您知道全局使用是否在您的文件中处于活动状态,如果您单击该图标,它将向您显示这些全局使用是什么。

The article C# language versioning explains how you can activate newer C# versions in older framework versions.文章C# 语言版本控制解释了如何在较旧的框架版本中激活较新的 C# 版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM