简体   繁体   English

我可以从命令行重命名C#符号吗?

[英]Can I rename a C# symbol from the command line?

Visual Studio has a "Refactor Rename" feature where I can right-click any type or member and rename it, and it will update all references within a project or solution to match. Visual Studio具有“重构重命名”功能,我可以右键单击任何类型或成员并重命名它,它将更新项目或解决方案中的所有引用以匹配。 Is this functionality accessible from MSBuild command line tools, without having to open Visual Studio? 是否可以从MSBuild命令行工具访问此功能,而无需打开Visual Studio?

(I'm doing this because I have a project that is so large that Visual Studio runs out of memory while attempting to calculate where the rename is needed). (我这样做是因为我有一个项目非常大,以至于Visual Studio在尝试计算需要重命名的位置时会耗尽内存)。

As far as I'm aware that's not something that's available outside of Visual Studio; 据我所知,这不是Visual Studio之外的东西; although you probably have a couple of avenues available for getting it done. 虽然你可能有几种方法可以完成它。

The first thing that I'd try is using a lighter editor, VSCode, Atom, etc. Something that uses less memory, but will still hopefully let you get the rename done. 我尝试的第一件事是使用更轻的编辑器,VSCode,Atom等。使用更少内存的东西,但仍然希望让你完成重命名。 You might have to use a regex find/replace to get it done; 可能必须使用正则表达式查找/替换才能完成它; whether that's an option kind of comes down to if you can make an accurate regex. 如果你可以制作一个准确的正则表达式,那么这是一种选择吗?

If you can actually get the project open in VS with no (or less, at least) problems, then you could also start unloading projects that aren't relevant to the rename. 如果您实际上可以在VS中打开项目而没有(或更少,至少)问题,那么您也可以开始卸载与重命名无关的项目。 If you know that it's only available in certain projects then unload everything else, perform your rename, and reload the projects. 如果您知道它仅在某些项目中可用,则卸载其他所有内容,执行重命名并重新加载项目。 If it's everywhere then you might still be able to do something similar to this, perform the rename in a few projects, unload them, load the next few, rename, etc. Although I'm honestly not 100% sure that'll work, I've never attempted it. 如果它在任何地方,那么你仍然可以做类似的事情,在几个项目中执行重命名,卸载它们,加载下几个,重命名等等。虽然我老实说不是100%确定它会工作,我从未尝试过。

Regardless of what you try, if you haven't already be sure to have your code in source control just in case. 无论你尝试什么,如果你还没有确定你的代码在源代码管理中以防万一。 I'm sure this is doable, but maybe not via the VS command line. 我确信这是可行的,但可能不是通过VS命令行。

No. There is no shipping msbuild target, task or tool to rename variables from the command line. 没有。没有运输msbuild目标,任务或工具来重命名命令行中的变量。

You could of course write yourself. 你当然可以写自己。 :) :)

But I highly suggest using Visual Studio Code as an alternative to Visual Studio for loading large numbers of projects. 但我强烈建议使用Visual Studio Code作为Visual Studio的替代方案来加载大量项目。 It's an outstanding cross platform IDE. 它是一个出色的跨平台IDE。 And who knows, perhaps someone wrote a plugin for it to rename variables...?? 谁知道,也许有人写了一个插件来重命名变量......?

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

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