是否有工具可以 select 一段代码并将其保存在 Visual Studio 2019 年的单独文件中?
Is there a facility to select a section of code and save it a seperate file in Visual Studio 2019?
我处理大型 html 文件,我想将它们分成单独的文件。这样做的过程非常繁琐,因为它需要复制代码,创建一个新文件,将其粘贴到新文件中,然后选择一个文件夹和一个名称来保存它。
Visual Studio 2017 及更高版本是否有内置的快捷方式或扩展程序来简化此操作?
您可以使用我的 Visual Commander 扩展程序在 Visual Studio 中自动执行它。 Select代码并调用以下命令(C#语言):
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
string currentFileName = DTE.ActiveDocument.FullName;
string newFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(currentFileName), System.IO.Path.GetFileNameWithoutExtension(currentFileName) + "NewPart" + System.IO.Path.GetExtension(currentFileName));
EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
System.IO.File.WriteAllText(newFileName, ts.Text);
}
}
我处理大型 html 文件,我想将它们分成单独的文件。这样做的过程非常繁琐,因为它需要复制代码,创建一个新文件,将其粘贴到新文件中,然后选择一个文件夹和一个名称来保存它。
Visual Studio 2017 及更高版本是否有内置的快捷方式或扩展程序来简化此操作?
您可以使用我的 Visual Commander 扩展程序在 Visual Studio 中自动执行它。 Select代码并调用以下命令(C#语言):
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
string currentFileName = DTE.ActiveDocument.FullName;
string newFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(currentFileName), System.IO.Path.GetFileNameWithoutExtension(currentFileName) + "NewPart" + System.IO.Path.GetExtension(currentFileName));
EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
System.IO.File.WriteAllText(newFileName, ts.Text);
}
}