简体   繁体   English

使 Visual Studio 2019 看到 git 存储库存在于源代码中但不在构建目录中(其中包含 sln 文件)

[英]Making Visual Studio 2019 see the git repo present in source but not in the build dir (which has the sln file)

I'm working on an existing, large open-source project that doesn't like in-source-tree builds.我正在开发一个不喜欢 in-source-tree 构建的现有大型开源项目。 So its cmake-generated .sln file is placed in the build dir that has no .git anywhere in its parent directories because that .git is in the disjoint source tree.因此,其 cmake 生成的.sln文件被放置在其父目录中没有.git的构建目录中,因为.git位于不相交的源代码树中。

\build
  \proj.sln
\src
  \.git

How do I make Visual Studio 2019 still see these "sideways".git files?如何让 Visual Studio 2019 仍能看到这些“侧身”.git 文件? It can see the (C++ etc.) sources referred in the sln, of course, but nothing relating to git works inside VS2019 in this setup, by default.当然,它可以看到 sln 中提到的(C++ 等)源,但默认情况下,在此设置中,与 git 相关的任何内容都无法在 VS2019 中运行。

在此处输入图像描述

I'm guessing I could mess with GIT_DISCOVERY_ACROSS_FILESYSTEM but I'm not sure it that would work with the way VS does git.我猜我可能会弄乱GIT_DISCOVERY_ACROSS_FILESYSTEM但我不确定它是否会与 VS 执行 git 的方式一起使用。

(And yes, the src dir is a git-cloned repo. I've made commits in it etc., but from the command line.) (是的, src目录是一个 git 克隆的存储库。我已经在其中进行了提交等,但是是从命令行进行的。)

And if I F1 (for help) the "Git Global Settings" in VS 2019... it goes to an oops page so that isn't exactly helpful.如果我 F1(寻求帮助)VS 2019 中的“Git 全局设置”......它会进入一个oops 页面,所以这并不是很有帮助。 Ok, I found the actual VS doc/help for git .好的,我找到了git 的实际 VS 文档/帮助 But it doesn't really answer my question.但它并没有真正回答我的问题。

If instead of opening the sln file, I open the directory of the source ( src ) from VS, then VS sees the git repo ok (current branch and what not)... but I can't build anything, because VS can't see/find the sln file in this context.如果不是打开 sln 文件,而是从 VS 打开源目录( src ),那么 VS 会看到 git 存储库正常(当前分支和其他分支)......但我无法构建任何东西,因为 VS 可以在此上下文中查看/查找 sln 文件。 So, how do I "have my cake and eat it", ie have VS see the git stuff and allow me to build?那么,我如何“吃掉我的蛋糕”,即让 VS 看到 git 的东西并允许我构建?

For testing, try and launch Visual Studio from a CMD where you type first:为了进行测试,请尝试从您首先键入的 CMD 启动 Visual Studio:

set GIT_DIR=C:\path\to\.git
cd C:\path\to\proj
.\proj.sln

(assuming the .sln extension is associated with devenv.exe ) (假设.sln扩展名与devenv.exe相关联)

I've made VS see the git repo (from within the sln) by manually adding a .git file in the build directory with just this contents:通过在构建目录中手动添加一个.git文件,我已经让 VS 看到了 git 存储库(来自 sln):

gitdir: X:/full-path-to-repo/.git/worktrees/src

I had forgotten to mention that the src was also a worktree, but that probably didn't make a diff (they also have.git file).我忘了提到 src 也是一个工作树,但这可能没有产生差异(他们也有.git 文件)。

Unlike the GIT_DIR environment variable, this .git -file method of telling where there repo is, isn't ignored by VS's git implementation.与 GIT_DIR 环境变量不同,VS 的 git 实现不会忽略此.git -file 方法来告知存储库在哪里。

But there's a big problem with this (too), VS now thinks it should add all those build object files to the repo: It thinks there are some 4,000 A-type changes,-( So. for this to be a real solution, I'd also need to able to tell it not do that somehow. (This might be ok for a smaller project. but writing filters for all those cmake-made files is going to be challenge in my case...)但是这也有一个大问题,VS 现在认为它应该将所有构建 object 文件添加到 repo:它认为有大约 4,000 个 A 型更改,-( 所以。要成为一个真正的解决方案,我'还需要能够告诉它不要以某种方式这样做。(这对于一个较小的项目来说可能没问题。但在我的情况下为所有这些 cmake 制作的文件编写过滤器将是一个挑战......)

在此处输入图像描述

在此处输入图像描述


Also, for an alternative approach if I install the cmake workload in VS and open the source folder again (instead of the sln), VS makes a big mess by immediately trying to do an in-source build, and with completely wrong, auto-generated settings, like using Ninja for some reason when this project doesn't use it at all.此外,对于另一种方法,如果我在 VS 中安装 cmake 工作负载并再次打开源文件夹(而不是 sln),VS 会立即尝试进行源内构建,并且完全错误,自动生成的设置,例如当这个项目根本不使用它时出于某种原因使用 Ninja。 So it seems there are "miles to go" for VS to be fully useable with cmake projects like this...因此,对于像这样的 cmake 项目来说,VS 似乎还有“数英里的路要走”......

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

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