简体   繁体   English

为什么我的生成的.sln文件不会在Visual Studio 2010中打开?

[英]Why won't my generated .sln file open in Visual Studio 2010?

I'm dealing with a fairly large C++ code base. 我正在处理一个相当大的C ++代码库。 The code base is normally intended to be compiled under Linux, using custom build scripts and makefiles. 代码库通常用于在Linux下编译,使用自定义构建脚本和makefile。 I'm porting the code into Visual Studio, which as anyone who's used Visual Studio would agree, is a pain to do manually. 我正在将代码移植到Visual Studio中,因为任何使用Visual Studio的人都会同意,这是一种手动操作的痛苦。

My own looking has been kind of fruitless, so I started writing my own utility in Qt to analyze the codebase and generate a solution file and accompanying .vcxproj files. 我自己看起来有点没用,所以我开始在Qt中编写自己的实用程序来分析代码库并生成一个解决方案文件和随附的.vcxproj文件。 I've been using the QUuid class to generate GUIDs for each of the projects, and I'm using QTextStream to write the .sln file. 我一直在使用QUuid类为每个项目生成GUID,我正在使用QTextStream来编写.sln文件。

Now, here's the problem: When I open the generated .sln file, I see the following errors. 现在,问题出现了:当我打开生成的.sln文件时,我看到以下错误。 所选文件不是有效的解决方案文件该系统找不到指定的文件

I'm currently trying to generate a solution that I've already manually created within the Visual Studio IDE. 我目前正在尝试生成一个我已经在Visual Studio IDE中手动创建的解决方案。 I've compared my generated .sln file against the the one Visual Studio created, and apart from the projects appearing in a different order and the GUIDs not matching (obviously), I can't spot a difference. 我将生成的.sln文件与Visual Studio创建的文件进行了比较,除了以不同顺序出现的项目和GUID不匹配(显然)之外,我无法发现差异。 I'm including a simplifed example of my problem here. 我在这里提供了一个简化的问题示例。

Visual Studio generated this: Visual Studio生成了这个:

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mylib", "mylib\mylib.vcxproj", "{35BAFEEE-35FA-4313-AF67-AF8AB7458451}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Win32 = Debug|Win32
        Release|Win32 = Release|Win32
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {35BAFEEE-35FA-4313-AF67-AF8AB7458451}.Debug|Win32.ActiveCfg = Debug|Win32
        {35BAFEEE-35FA-4313-AF67-AF8AB7458451}.Debug|Win32.Build.0 = Debug|Win32
        {35BAFEEE-35FA-4313-AF67-AF8AB7458451}.Release|Win32.ActiveCfg = Release|Win32
        {35BAFEEE-35FA-4313-AF67-AF8AB7458451}.Release|Win32.Build.0 = Release|Win32
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal

And I generated this: 我生成了这个:

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mylib", "mylib\mylib.vcxproj", "{A09FDB84-49CD-4C14-9D7D-D813D2D905EF}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Win32 = Debug|Win32
        Release|Win32 = Release|Win32
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {A09FDB84-49CD-4C14-9D7D-D813D2D905EF}.Debug|Win32.ActiveCfg = Debug|Win32
        {A09FDB84-49CD-4C14-9D7D-D813D2D905EF}.Debug|Win32.Build.0 = Debug|Win32
        {A09FDB84-49CD-4C14-9D7D-D813D2D905EF}.Release|Win32.ActiveCfg = Release|Win32
        {A09FDB84-49CD-4C14-9D7D-D813D2D905EF}.Release|Win32.Build.0 = Release|Win32
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal

Here are my questions: 这是我的问题:

  1. What do these specifc error messages mean? 这些特定错误消息的含义是什么?
  2. Is there any way I can get more specific information on what's wrong with the .sln file? 有什么方法可以获得有关.sln文件错误的更具体信息吗?
  3. Is there something wrong with the GUIDs I'm generating? 我正在生成的GUID有什么问题吗? Should I be using the Visual Studio tool to create GUIDs? 我应该使用Visual Studio工具来创建GUID吗?
  4. Is there some metadata or other invisible special sauce in the file that I'm missing? 我丢失的文件中是否有一些元数据或其他隐形特殊酱?

I'm pretty sure the issue isn't with text encoding--I used notepad to create a UTF-8 version of the .sln and tried opening that instead. 我很确定问题不在于文本编码 - 我使用记事本来创建.sln的UTF-8版本并尝试打开它。

In light of everything, it seems like my GUIDs are causing the issue--though I'm not sure how or why. 鉴于一切,似乎我的GUID导致问题 - 虽然我不知道如何或为什么。

Update 更新

The only major difference I noticed between these files was the file size. 我注意到这些文件之间唯一的主要区别是文件大小。 The two files differ by exactly 3 bytes, but I couldn't see anything in the file using my text editor. 这两个文件恰好相差3个字节,但是我无法使用文本编辑器在文件中看到任何内容。 However, an article by Joel Spolsky got me thinking. 然而, Joel Spolsky的一篇文章让我思考。 There ain't no such thing as plain text--everything's just a representation of 1's and 0's, after all. 没有普通文本这样的东西 - 毕竟,一切只是1和0的表示。

I opened up the two files in a hex editor, and presto, I found the 3 bytes at the start of the Microsoft-generated file! 我在十六进制编辑器中打开了两个文件,然后我在Microsoft生成的文件的开头找到了3个字节! ( 0xEF, 0xBB, 0xBF ). 0xEF, 0xBB, 0xBF )。 These three bytes also appear in a Visual Studio 2008 solution I had lying around on a different machine. 这三个字节也出现在我在另一台机器上躺着的Visual Studio 2008解决方案中。 I could probably write my code to slip these bytes into the file before I start writing the solution, but that still begs the question: 在开始编写解决方案之前,我可能会编写我的代码将这些字节放入文件中,但这仍然引出了一个问题:

What the heck are these bytes for, and why is Microsoft using them? 这些字节到底是什么,为什么微软会使用它们?

What you are contemplating is a UTF-8 byte order mark . 您正在考虑的是UTF-8字节顺序标记

It is used to indicate that the file is UTF-8 encoded, and it is supposed to be rendered as a blank, zero width space. 它用于指示文件是UTF-8编码的,并且应该将其呈现为空的零宽度空间。 If you have the choice, please don't use it -- it makes the file more difficult to read with standard text editors. 如果您有选择,请不要使用它 - 它使文件更难以阅读标准文本编辑器。

Opening the file with notepad and saving it as UTF-8 encoded text will add those three bytes for you. 使用记事本打开文件并将其保存为UTF-8编码文本将为您添加这三个字节。 But again, don't use the BOM on files which are meant to be portably read. 但是,请不要在可以便携式读取的文件上使用BOM。

Debug Visual Studio with Visual Studio: 使用Visual Studio调试Visual Studio:

Before opening your generated solution with Visual Studio, open another instance of Visual Studio, go to Debug->Exceptions and check all the check boxes, then go to Debug->Attach to Process... and attach to devenv.exe . 在使用Visual Studio打开生成的解决方案之前,打开另一个Visual Studio实例,转到Debug->Exceptions并选中所有复选框,然后转到Debug->Attach to Process...并附加到devenv.exe Now open the solution in the other VS, and you'll get a break and a call stack which might give you more information. 现在打开另一个VS中的解决方案,您将获得一个中断和一个调用堆栈,它可能会为您提供更多信息。

To add to the answer I accepted, in the case of Qt, I made use of the following method in the QTextStream object I was using to write the solution file: 为了添加我接受的答案,在Qt的情况下,我在我用来编写解决方案文件的QTextStream对象中使用了以下方法

void QTextStream::setGenerateByteOrderMark ( bool generate )

Syntax is like so: 语法是这样的:

QFile fileHandle("mylib.sln");
QTextStream fileStream(&fileHandle);
// ...file open and error handling goes here...
fileStream.setGenerateByteOrderMark(true);
fileStream << "\nMicrosoft Visual Studio Solution File, Format Version 11.00\n";
//etc, etc

This will make sure that your file has the Byte Order Mark, which in this specific case, Visual Studio needs in order to open the file. 这将确保您的文件具有字节顺序标记,在此特定情况下,Visual Studio需要打开该文件。

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

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