.net 如何强制在 Visual Studio 2013 中打开解决方案文件 (SLN)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19513306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:31:26  来源:igfitidea点击:

How to force a Solution file (SLN) to be opened in Visual Studio 2013?

.netvisual-studio-2012solutionvisual-studio-2013

提问by Uwe Keim

Trying to open a VS 2012 solution (SLN file) explicitly in VS 2013 succeeds. Simply double-clicking it in Windows Explorer still opens it in VS 2012 instead.

尝试在 VS 2013 中显式打开 VS 2012 解决方案(SLN 文件)成功。只需在 Windows 资源管理器中双击它仍然会在 VS 2012 中打开它。

I've read "Visual Studio 2012 doesn't convert vs2010 solution?" and followed the suggestion to "Save As..." the solution file.

我已阅读“ Visual Studio 2012 不转换 vs2010 解决方案?”并按照建议“另存为...”解决方案文件

Still it opens in VS 2012 by default.

它仍然默认在 VS 2012 中打开。

My question:

我的问题:

How to change a SLN file to force it being opened in Visual Studio 2013?

如何更改 SLN 文件以强制在 Visual Studio 2013 中打开它?

回答by Marc Gravell

The .slnfile indicates the intendedversion as one of the early lines - for example:

.sln文件将预期版本指示为早期行之一 - 例如:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013

or:

或者:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012

However - it can only make use of this if the default application for .slnfiles is the "Microsoft Visual Studio Version Selector". It is not uncommon for the default .slnapplication to be a specificversion instead. In windows 8:

但是 - 如果.sln文件的默认应用程序是“Microsoft Visual Studio 版本选择器”,它只能使用此功能。默认.sln应用程序改为特定版本的情况并不少见。在 Windows 8 中:

enter image description here

在此处输入图片说明

you can tell which is the default because it says "keep using":

您可以判断哪个是默认值,因为它说“继续使用”:

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by zumey

Note that you can also force the upgrade of a .sln or .proj file by using the commandline, where devenv is the target IDE version:

请注意,您还可以使用命令行强制升级 .sln 或 .proj 文件,其中 devenv 是目标 IDE 版本:

devenv "MyProject.sln" /upgrade

Example:

例子:

"%programfiles(x86)%\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" "D:\Source\MySolution.sln" /upgrade

Note that this does not open Visual Studio. An alternative is to, from within the IDE, select "Save As" for your solution file and overwrite or save the solution under new name.

请注意,这不会打开 Visual Studio。另一种方法是,在 IDE 中,为您的解决方案文件选择“另存为”,并以新名称覆盖或保存解决方案。

Read more: http://msdn.microsoft.com/en-us/library/w15a82ay.aspx

阅读更多:http: //msdn.microsoft.com/en-us/library/w15a82ay.aspx

回答by TCC

Seems like the OP has a working answer already ... but for me the problem was different. I had a VS 2012 solution (several actually) and wanted to convert them to 2013 (which I understand is a trivial change to the .sln file, but I wanted it done automatically in case there was some secret upgrade logic I was unaware of).

似乎 OP 已经有了一个有效的答案……但对我来说,问题是不同的。我有一个 VS 2012 解决方案(实际上有几个)并想将它们转换为 2013(我理解这是对 .sln 文件的一个微不足道的更改,但我希望它自动完成,以防有一些我不知道的秘密升级逻辑) .

So I thought I would open it in VS2013, it would automatically upgrade as expected, and then I'd be set to double click the solution and see it in VS2013 going forward. But opening in VS2013 was NOT upgrading the solution for me automatically as expected and I could not find an explicit way to force the upgrade after opening the file in VS2013. I could work with the solution, save my changes, and close VS2013, but the .sln would remain unchanged and un-upgraded.

所以我想我会在VS2013中打开它,它会按预期自动升级,然后我会被设置为双击解决方案并在VS2013中看到它。但是在 VS2013 中打开并没有像预期的那样自动为我升级解决方案,并且在 VS2013 中打开文件后我找不到强制升级的明确方法。我可以使用该解决方案,保存更改并关闭 VS2013,但 .sln 将保持不变且未升级。

Turns out my problem was in how I was opening the solution ... as a habit I right click files and select "open with" to choose the program I want to use to open a file. I do this frequently. Note I am NOT talking about changing the default "open with" program but just opening a file with a specific program once. So I would right click the .sln file... open with Visual Studio 2013 ... and nothing would upgrade.

原来我的问题在于我如何打开解决方案......作为一种习惯,我右键单击文件并选择“打开方式”以选择我想用来打开文件的程序。我经常这样做。注意我不是在谈论更改默认的“打开方式”程序,而只是用特定程序打开一个文件一次。所以我会右键单击 .sln 文件......用 Visual Studio 2013 打开......并且没有任何升级。

Eventually I thought to go into VS2013, then do File > Open and select the .sln file (this is foreign to me since I hardly if ever open anything this way, maybe you are the same way). Anyway that did upgrade the solution file instantly.

最终我想进入 VS2013,然后执行 File > Open 并选择 .sln 文件(这对我来说很陌生,因为我几乎没有以这种方式打开任何东西,也许你也是这样)。无论如何,这确实立即升级了解决方案文件。

After upgrading, lines 2-3 of the .sln file changed from this:

升级后,.sln 文件的第 2-3 行更改为:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012

to this:

对此:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
MinimumVisualStudioVersion = 10.0.40219.1

So from my experience, to automatically update a VS2012 .sln to VS2013, you must open VS2013 and select the .sln from the File > Open dialog. Using the explorer shell to force the .sln file to open in VS2013 does not invoke the upgrade logic (apparently).

因此,根据我的经验,要将 VS2012 .sln 自动更新为 VS2013,您必须打开 VS2013 并从“文件”>“打开”对话框中选择 .sln。使用资源管理器外壳强制 .sln 文件在 VS2013 中打开不会调用升级逻辑(显然)。

As a further note, I tested with another solution, and after making changes through Configuration Manager (which obviously "touches" the .sln file) it did upgrade a VS2012 to VS2013, even after having opened it through right-click open with.

进一步说明,我使用另一个解决方案进行了测试,在通过配置管理器(它显然“触及”了 .sln 文件)进行了更改后,它确实将 VS2012 升级到了 VS2013,即使在通过右键单击打开方式打开它之后也是如此。

回答by Jeff

I had a solution that had previously been upgraded from 2010 to 2013 successfully but still showed the .sln as associated with 2010.

我有一个以前已成功从 2010 升级到 2013 的解决方案,但仍显示与 2010 相关的 .sln。

I tested all the methods given in this thread and the only one that successfully corrected the .sln was to open Visual Studio 2013 alone, then open the solution that still was associated with 2010 in the IDE, then use the [File] > [Save (name).sln as] to overwrite the existing .sln file.

我测试了该线程中给出的所有方法,唯一成功纠正 .sln 的方法是单独打开 Visual Studio 2013,然后在 IDE 中打开仍与 2010 关联的解决方案,然后使用 [文件] > [保存(name).sln as] 覆盖现有的 .sln 文件。

Setting the file assoc of the .sln to be the "Visual Studio version selector" made no change and the solution continued to open in 2010.

将 .sln 的文件关联设置为“Visual Studio 版本选择器”没有任何改变,该解决方案在 2010 年继续打开。

The devenv (name).sln /upgrade method made no change to my .sln file.

devenv (name).sln /upgrade 方法没有改变我的 .sln 文件。

Hacking the raw text of the .sln file corrupted mine and it would not open at all.

破解 .sln 文件的原始文本损坏了我的文件,它根本无法打开。

回答by Zac

To solve this issue I just changed the following lines of the .sln file:

为了解决这个问题,我只是更改了 .sln 文件的以下几行:

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010

into these:

进入这些:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013

The comment line is to be changed as it is parsed by the solution loader.

注释行将在解决方案加载器解析时进行更改。

回答by Theophilus

This may work for readers attempting to upgrade a solution file to Visual Studio 2015. (I upgraded a VS 2012 solution.)

这可能适用于尝试将解决方案文件升级到 Visual Studio 2015 的读者。(我升级了 VS 2012 解决方案。)

  1. Open the solution in VS 2015.
  2. Add a new project to the solution. (I added a test project.)
  3. Remove the project.
  4. Save the solution.
  1. 在 VS 2015 中打开解决方案。
  2. 向解决方案添加一个新项目。(我添加了一个测试项目。)
  3. 删除项目。
  4. 保存解决方案。

You may want to delete the removed project folder at this time since step 3 did not delete it.

此时您可能希望删除已删除的项目文件夹,因为步骤 3 并未将其删除。

This worked for me when neither zumey'snor TCC'sanswers did.

zumeyTCC 的答案都没有时,这对我有用

EDIT

编辑

Metro Smurfhad a similar, but easier answer than mine for a similar question. His steps were:

Metro Smurf类似问题有一个类似但比我更容易的答案。他的步骤是:

  1. Open solution in VS 2015
  2. Right-click solution > Add > New Solution Folder (name does not matter)
  3. Save solution
  4. Delete the newly added solution folder
  5. Save solution
  1. VS 2015 中的开放解决方案
  2. 右键单击解决方案 > 添加 > 新建解决方案文件夹(名称无关紧要)
  3. 保存解决方案
  4. 删除新添加的解决方案文件夹
  5. 保存解决方案