简体   繁体   English

Visual Studio不断更改project.sln文件

[英]Visual Studio keeps changing project.sln file

I work in a team on a Visual C++ project. 我在Visual C ++项目的团队中工作。 Following advice we got we're tracking the project's .sln file with our SCM. 根据我们的建议,我们使用SCM跟踪项目的.sln文件。 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. 事实证明,每次我从我的伙伴那里取消(是的,我们使用git)并在VS中打开解决方案,都会更新.sln文件。 The part being updated is the long id that appears several times (in this case ending with 7C44) in the following segment: 正在更新的部分是在以下段中多次出现的长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? 我们怎样才能让它在我们之间停止变化?

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 files when opening a solution? 因此,以更多方式提出问题: 为什么Visual Studio在打开解决方案时会更改.sln文件 Why do .sln files have local modifications? 为什么.sln文件有本地修改? or What causes merge conflicts in Visual Studio Solution files? 什么原因导致Visual Studio解决方案文件中的合并冲突?

Answer: Most likely a different or missing ProjectGuid attribute in the .vcxproj Project file will cause local modifications. 答:.vcxproj项目文件中很可能不同或缺少ProjectGuid属性将导致本地修改。 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. 这可能是由于从以前版本的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. 否则,Visual Studio将为每个项目分配一个新的随机ProjectGuid并更新.sln文件。 The 'ProjectGuid' can easily be found for a given project in the .sln file: 可以在.sln文件中轻松找到给定项目的'ProjectGuid':

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

That is a GUID which Visual Studio uses to refer to the individual projects. 这是Visual Studio用于引用各个项目的GUID。 You will find the same GUID at the top of the .sln file, where the projects are defined/imported. 您将在.sln文件的顶部找到相同的GUID,其中定义/导入项目。

Visual Studio reads the GUID from the corresponding .csproj/.vbproj file. Visual Studio从相应的.csproj / .vbproj文件中读取GUID。 There you should find a ProjectGuid property near the top with the corresponding GUID. 在那里你应该在顶部附近找到一个带有相应GUID的ProjectGuid属性。 If you and your partner have a different GUID defined there, the .sln will also update. 如果您和您的伙伴在那里定义了不同的GUID,.sln也将更新。

I've had the same problem. 我遇到了同样的问题。 I finally noticed it came from a vcxproj file which didn't define its GUID. 我终于注意到它来自一个没有定义其GUID的vcxproj文件。 I manually added this GUID in my vcxproj file : 我手动在我的vcxproj文件中添加了这个GUID:

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

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

相关问题 Visual Studio自动生成:Makefile与Project.sln - Visual Studio automated build: Makefile vs Project.sln 如何重定位 Visual Studio 项目 (.sln) 文件 - How to Relocate Visual Studio project (.sln) file 如何配置.sln Visual Studio Project文件存储在项目文件夹中? - How to configure .sln Visual Studio Project file to be stored in the project folder? 没有sln文件时使用Visual Studio 2015打开解决方案/项目 - Opening Solution / Project with Visual studio 2015 when there is no sln file 编辑Visual Studio .sln文件 - Edit Visual Studio .sln file 什么是在MacOS上的Visual Studio项目中不断更改的.DS_Store文件? - What's the .DS_Store file that keeps changing in my Visual Studio project on macOS? Visual Studio Git sln文件合并冲突 - Visual Studio Git sln file merge conflicts 将基于project.json的项目添加到.sln文件而不使用Visual Studio - Add a project.json based project to a .sln file without using Visual Studio 打开Visual Studio 2008 sln文件创建一个Visual Studio文件夹 - Opening a Visual Studio 2008 sln file creates a Visual Studio folder 如何在与Web项目相同的目录中创建Visual Studio解决方案文件(.sln)? - How do you create a Visual Studio Solution File (.sln) in the same directory as the web project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM