更改 Visual Studio 解决方案中所有项目的目标框架
我需要更改所有项目的目标框架。我有数百个项目的许多解决方案。
这里有什么新的东西还是我必须改变每个项目?
I need to change the target framework for all projects. I have many solutions with hundreds of projects.
Anything new here or do I have to change every single project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
刚刚发布了 目标框架迁移器,用于更改多个 .Net 项目目标框架的 Visual Studio 扩展,网址为一次
Just published Target Framework Migrator, Visual Studio Extension for changing multiple .Net projects Target Framework at once
您可以使用 CodeProject 上提供的 Scott Dorman 的 Visual Studio 宏来做到这一点:
下面是代码,将其下载到您的
\Documents\Visual Studio 2010\Projects\VSMacros80\MyMacros
文件夹,打开 Visual Studio Macro IDE (Alt-F11) 并添加它作为“MyMacros”项目的现有项目:You can do that using Scott Dorman's Visual Studio macro available on CodeProject:
Below is the code, download it to your
<UserProfile>\Documents\Visual Studio 2010\Projects\VSMacros80\MyMacros
folder, open the Visual Studio Macro IDE (Alt-F11) and add it as an existing item to the “MyMacros” project:我用来做我的 PowerShell 脚本。诚然,布鲁斯·武力相当。
A PowerShell script that I used to do mine. Admittedly bruce force-ish.
总有简单的。一个像notepad++这样的不错的文本编辑器将包含在文件中查找/替换的功能。只需在 csproj/vbproj 文件中搜索当前版本字符串:
并替换为新版本
不过,最好先检查一下......
There's always the simple. A decent text editor such as notepad++ will include a find/replace in files function. Just search for the current version string in your csproj/vbproj files:
and replace with the new version
Good idea to check out first though...
来自bash:
From bash:
我认为到目前为止最简单的方法是使用搜索和替换工具。如果它支持正则表达式,这是一个优势。
肯定有不少 - 不过,我测试的第一个对我有用: http://www.ecobyte.com/replacetext/" rel="noreferrer">http://www.ecobyte.com ecobyte.com/replacetext/
有一个说明说它在Win7上有一些问题,但我没有遇到过。
该工具中的分步说明:
.*
)4.0
)如果由于某种原因您需要执行此操作在代码中,我也可能能够做到这一点(这就是我发现这个问题的方式)。在这种情况下,请在评论中请求。
I think by far the easiest way to do this is using a search and replace tool. It is an advantage if it supports regex.
There must be quite a few out there - the first one I tested worked for me, though: http://www.ecobyte.com/replacetext/
There is a note saying it has some issues on Win7, but I didn't experience that.
Step by step instructions in that tool:
<TargetFrameworkVersion>.*</TargetFrameworkVersion>
)<TargetFrameworkVersion>4.0</TargetFrameworkVersion>
)Now If for some reason you need to do this in code, I would probably be able to do that as well (it's how I found this question). In that case, please request it in a comment.
目标框架迁移器,作者:Pavel Samokha (VHQLabs)
http://visualstudiogallery.msdn。 microsoft.com/47bded90-80d8-42af-bc35-4736fdd8cd13
Target Framework Migrator by Pavel Samokha (VHQLabs)
http://visualstudiogallery.msdn.microsoft.com/47bded90-80d8-42af-bc35-4736fdd8cd13
条件正则表达式让我很头疼。所以这里是一个用于搜索/替换的编码解决方案(我尽可能避免使用 EnvDTE)。
顺序似乎并不重要项目文件条目:
尝试一些类似的事情:
Conditional regexes are giving me a headache. So here is a coded solution for search/replace (I'm avoiding EnvDTE as long as possible).
Order does not seem to matter for the project file entries:
Try something along those lines:
您可以使用宏来执行此操作,或者记住 VS 项目文件是文本文件,这意味着简单的全局搜索和替换可以实现相同的目的,并且是对大量项目文件进行相同更改的更通用技术。
首先备份现有的项目文件,然后进行所需的更改(例如,更改目标框架)。使用 WinDiff 或 WinMerge 将新项目文件与备份进行比较。这将告诉您需要进行的更改。然后使用 Visual Studio IDE 的“在文件中查找和替换”功能对所有项目文件进行更改。
You can use a macro to do this, or remember that the VS project files are text files, which means a simple global search and replace can achieve the same, and is a more general technique for making the same change to lots of project files.
First back up an existing project file, then make the change you want (e.g., change the target framework). Use WinDiff or WinMerge to compare the new project file with the back up. This will tell you the change you need to make. Then use the Visual Studio IDE's Find and Replace in Files function to make the change to all your project files.
没有外部工具的替代方案(并且能够更改其他设置,例如 ToolsVersion):
这可以轻松扩展到其他项目类型。
An alternative with no external tools (and the ability to change other settings, e.g. ToolsVersion):
This can easily be extended for other project types.