visual-studio Visual Studio 不断更改 project.sln 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4194424/
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-10-22 12:46:24  来源:igfitidea点击:

Visual Studio keeps changing project.sln file

visual-studioversion-controlprojects-and-solutions

提问by Jonathan

I work in a team on a Visual C++ project. Following advicewe got we're tracking the project's .sln file with our SCM. It turns out that each time I pull from my partner (yes, we use git) and open the solution in VS, the .sln file is updated. The part being updated is the long id that appears several times (in this case ending with 7C44) in the following segment:

我在一个团队中从事 Visual C++ 项目。根据我们得到的建议,我们正在使用 SCM 跟踪项目的 .sln 文件。事实证明,每次我从我的伙伴那里拉取(是的,我们使用 git)并在 VS 中打开解决方案时,.sln 文件都会更新。正在更新的部分是在以下段中多次出现的长 ID(在本例中以 7C44 结尾):

    {828CB89E-F092-3B7A-2F8C-62E146587C44}.Debug|Win32.ActiveCfg = Debug|Win32
    {828CB89E-F092-3B7A-2F8C-62E146587C44}.Debug|Win32.Build.0 = Debug|Win32
    {828CB89E-F092-3B7A-2F8C-62E146587C44}.DebugStaticCRT|Win32.ActiveCfg = DebugStaticCRT|Win32
    {828CB89E-F092-3B7A-2F8C-62E146587C44}.DebugStaticCRT|Win32.Build.0 = DebugStaticCRT|Win32
    {828CB89E-F092-3B7A-2F8C-62E146587C44}.Release|Win32.ActiveCfg = Release|Win32
    {828CB89E-F092-3B7A-2F8C-62E146587C44}.Release|Win32.Build.0 = Release|Win32
    {828CB89E-F092-3B7A-2F8C-62E146587C44}.ReleaseStaticCRT|Win32.ActiveCfg = ReleaseStaticCRT|Win32
    {828CB89E-F092-3B7A-2F8C-62E146587C44}.ReleaseStaticCRT|Win32.Build.0 = ReleaseStaticCRT|Win32
    {828CB89E-F092-3B7A-2F8C-62E146587C44}.Template|Win32.ActiveCfg = Template|Win32
    {828CB89E-F092-3B7A-2F8C-62E146587C44}.Template|Win32.Build.0 = Template|Win32

What does this number mean? How can we make it stop changing between us?

这个数字是什么意思?我们怎样才能让它在我们之间停止变化?

采纳答案by Daniel Rose

That is a GUID which Visual Studio uses to refer to the individual projects. You will find the same GUID at the top of the .sln file, where the projects are defined/imported.

这是一个 GUID,Visual Studio 使用它来引用各个项目。您将在 .sln 文件的顶部找到相同的 GUID,其中定义/导入了项目。

Visual Studio reads the GUID from the corresponding .csproj/.vbproj file. There you should find a ProjectGuid property near the top with the corresponding GUID. If you and your partner have a different GUID defined there, the .sln will also update.

Visual Studio 从相应的 .csproj/.vbproj 文件中读取 GUID。您应该在顶部附近找到一个带有相应 GUID 的 ProjectGuid 属性。如果您和您的合作伙伴在那里定义了不同的 GUID,.sln 也会更新。

回答by Devan Williams

I had a difficult time finding this particular post when searching for the answer, so I just wanted to add some key words and explanation to make it easier to find. Thanks to the fantastic answers by Daniel and tgb I was able to resolve this issue and my team and I no longer have conflicting solution files after opening Visual Studio 2010 (I would vote their answers up, but I just joined today and do not yet have enough reputation points to vote answers up...).

我在搜索答案时很难找到这个特定的帖子,所以我只想添加一些关键词和解释,以便更容易找到。感谢 Daniel 和 tgb 的精彩回答,我能够解决这个问题,我的团队和我在打开 Visual Studio 2010 后不再有冲突的解决方案文件(我会投票支持他们的答案,但我今天刚刚加入,还没有足够的声望点来投票回答......)。

So, to ask the question in a few more ways: Why does Visual Studio change .sln fileswhen opening a solution? Why do .sln files have local modifications?or What causes merge conflicts in Visual Studio Solution files?

那么,多问几个问题: 为什么 Visual Studio在打开解决方案时会更改 .sln 文件为什么 .sln 文件有本地修改?什么导致 Visual Studio 解决方案文件中的合并冲突?

Answer: Most likely a different or missing ProjectGuid attribute in the .vcxproj Project file will cause local modifications. This could be due to upgrading projects from previous versions of Visual Studio or just from manually copying a project file and editing parts of it.

回答: .vcxproj 项目文件中的不同或缺失的 ProjectGuid 属性很可能会导致本地修改。这可能是由于从以前版本的 Visual Studio 升级项目,或者只是手动复制项目文件并编辑其中的一部分。

The fix is to add the line:

解决方法是添加以下行:

<ProjectGuid>{###}</ProjectGuid>

(with the appropriate ID from the solution file in place of ###) to the .vcxproj file in the 'PropertyGroup Label="Globals"' node, for example:

(使用解决方案文件中的适当 ID 代替 ###)到 'PropertyGroup Label="Globals"' 节点中的 .vcxproj 文件,例如:

  <PropertyGroup Label="Globals">
    <ProjectGuid>{FD0675C0-EC06-E665-4001-12DEE6694605}</ProjectGuid>
    <RootNamespace>MyProject</RootNamespace>
  </PropertyGroup>

Otherwise Visual Studio will just assign a new random ProjectGuid to each project and update the .sln file. The 'ProjectGuid' can easily be found for a given project in the .sln file:

否则 Visual Studio 只会为每个项目分配一个新的随机 ProjectGuid 并更新 .sln 文件。可以在 .sln 文件中轻松找到给定项目的“ProjectGuid”:

Project("{<Filter#>}") = "MyProjName", "src\to\Proj.vcxproj", "{<ProjectGuid>}"

回答by tgb

I've had the same problem. I finally noticed it came from a vcxproj file which didn't define its GUID. I manually added this GUID in my vcxproj file :

我遇到了同样的问题。我终于注意到它来自一个没有定义其 GUID 的 vcxproj 文件。我在我的 vcxproj 文件中手动添加了这个 GUID:

  <PropertyGroup Label="Globals">
    <ProjectGuid>{D3303AD3-B7E5-48F8-919C-18202ABAEF00}</ProjectGuid>
    <RootNamespace>MyProject</RootNamespace>
    <ProjectName>MyProject</ProjectName>
    <Keyword>MFCProj</Keyword>
  </PropertyGroup>