VS 破坏解决方案文件

发布于 2024-12-03 14:49:16 字数 922 浏览 0 评论 0原文

我有一个(python)脚本,可以完成以下任务:

  1. 扫描文件夹以查找 .csproj.vcproj 文件。
  2. 根据 .csproj.vcproj 文件编写文本,创建一个包含所有项目的解决方案文件。
  3. 构建该解决方案。通过从命令行调用 devenv.exe /Build(Python 上的 subprocess.call)。

我的问题是:当我构建时,VS 更改了我的 SLN 中的配置。具体来说,在 SLN 的 Win32 配置上,所有 .csproj 项目(.NET 项目)从 x86 切换到 x64并从构建中标记出来。

尝试没有成功: 更改 SLN,使所有 .NET 位于 x86 上,而 VC 位于 x86 解决方案配置下的 Win32 上。再次,VS 在打开 SLN 时破坏了它:VC 会自动更改为目标 x64 并标记为在构建之外。

尝试有效但相当笨拙: 首先,我让 VS 破坏文件。我设法做到这一点的唯一笨拙的方法是从命令行调用 /Build 然后调用 /Clean 。接下来,我通过替换 VS 损坏的配置来修复 SLN 文件。现在,当我 /Build 它时,VS 不会更改 SLN。

那么:

  1. 有人有更优雅的解决方案吗?
  2. 除了 /Build - /Clean 之外,还有什么更好的方法可以让 VS 破坏文件?

I have a (python) script that accomplishes the following:

  1. Scanning a folder looking for .csproj and .vcproj files.
  2. Creating a solution file to contain all the projects by writing text according to the .csproj and .vcproj files.
  3. Building that solution. By calling devenv.exe /Build from command line (subprocess.call on python).

My problem is: When I build, VS changes configuration in my SLN. Specifically, on SLN's Win32 configuration, all the .csproj projects (.NET projects) switch from x86 to x64 and are marked out from the build.

Attempt that did not work:
Changing the SLN to have all the .NETs at x86 and the VCs on Win32 under x86 solution config. Again, VS breaks it when it opens the SLN : VCs are automatically change to target x64 and marked out of the build.

Attempt that worked but quite clumsy:
First, I let VS break the file. The only clumsy way that I managed to do that is calling /Build then /Clean from command line. Next, I fix the SLN file by replacing the configs that VS broke. And now when I /Build it, VS does not alter the SLN.

So:

  1. Anyone with a more elegant solution ?
  2. Any nicer way to make VS break the file other then /Build - /Clean ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬心 2024-12-10 14:49:16

简单的答案是,缩进对于 VS sln 解析器很重要。

所以公司的人声称这一切在当天都有效,我发现很难相信。我一遍又一遍地扫描构建它的代码和生成的 sln 文件,但看不出任何区别。

因为我没有看空格!

一个月前,我无意中更改了构建 .sln 文件的代码,以使用不同的缩进写入该文件。

这是文件的区别:

这有效,因为该文件与 VS 制作的文件相同,包括缩进:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{19091980-2008-4CFA-1491-04CC20D8BCF9}") = "proj1", "..\proj1_2008.vcproj", "{C844505D-3D9E-437F-94D6-BDA74999651D}"
...
EndProject
Project ...
..
EndProject
Global
Global
  GlobalSection(SolutionConfigurationPlatforms) = preSolution
*good     Debug|Win32 = Debug|Win32
          Debug|x64 = Debug|x64
          Release|Win32 = Release|Win32
          Release|x64 = Release|x64
  EndGlobalSection
  ....

这个文件导致 VS 重新编辑,并且作为副作用破坏了我们所需的解决方案配置:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{19091980-2008-4CFA-1491-04CC20D8BCF9}") = "proj1", "..\proj1_2008.vcproj", "{C844505D-3D9E-437F-94D6-BDA74999651D}"
...
EndProject
Project ...
..
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
*bad    Debug|Win32 = Debug|Win32
*indent-Debug|x64 = Debug|x64
*ation  Release|Win32 = Release|Win32
        Release|x64 = Release|x64
    EndGlobalSection
    ....

The simple answer is, indentation matters to the VS sln parser.

So folks at the company claimed it all worked back in the day, and I found it hard to believe. Over and over again I scanned the code that builds it and the sln file that is produced and couldn't tell any difference.

Beacuse I didn't look at whitespaces !

Month ago I innocently changed the code that builds the .sln file to write the file with different indentation.

Here's the difference of the files:

That worked, because the file was identical to a VS-made file, including the indenetation:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{19091980-2008-4CFA-1491-04CC20D8BCF9}") = "proj1", "..\proj1_2008.vcproj", "{C844505D-3D9E-437F-94D6-BDA74999651D}"
...
EndProject
Project ...
..
EndProject
Global
Global
  GlobalSection(SolutionConfigurationPlatforms) = preSolution
*good     Debug|Win32 = Debug|Win32
          Debug|x64 = Debug|x64
          Release|Win32 = Release|Win32
          Release|x64 = Release|x64
  EndGlobalSection
  ....

This one caused VS to re-edit, and as a side eefect to break our desired solution configuration:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{19091980-2008-4CFA-1491-04CC20D8BCF9}") = "proj1", "..\proj1_2008.vcproj", "{C844505D-3D9E-437F-94D6-BDA74999651D}"
...
EndProject
Project ...
..
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
*bad    Debug|Win32 = Debug|Win32
*indent-Debug|x64 = Debug|x64
*ation  Release|Win32 = Release|Win32
        Release|x64 = Release|x64
    EndGlobalSection
    ....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文