“添加为链接”对于 Visual Studio 项目中的文件夹

发布于 2024-09-16 21:23:59 字数 127 浏览 5 评论 0原文

在Visual Studio中,我们可以“添加为链接”来添加指向解决方案中另一个项目中的文件的链接。

有没有办法对整个文件夹执行此操作,以便项目 A 中的整个文件夹在项目 B 中可见,而无需手动链接到该文件夹​​中的新项目?

In Visual Studio, we can "Add as link" to add a link to a file in another project in the solution.

Is there any way to do this for entire folders, so that an entire folder in project A will be visible in project B, without the need to manually link to new items in that folder?

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

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

发布评论

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

评论(8

清泪尽 2024-09-23 21:23:59

正如这个 博客文章指出,这是可能的。

<ItemGroup>
    <Compile Include="any_abs_or_rel_path\**\*.*">
        <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
    </Compile>
</ItemGroup>

但请注意,文件不会被复制。

As this blogpost stated, it is possible.

<ItemGroup>
    <Compile Include="any_abs_or_rel_path\**\*.*">
        <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
    </Compile>
</ItemGroup>

But be aware, the files will not be copied.

偷得浮生 2024-09-23 21:23:59

在 VS2012 及更高版本中,您可以按住 alt 键将文件夹拖到另一个项目。这与手动添加每个文件作为链接相同,但速度更快。

更新
如果您使用的是 VS2013 update 2(带有 共享项目参考管理器)或 VS2015。

In VS2012 and later, you can drag a folder to another project with alt key pressed. It's just the same as adding each file as link manually but faster.

upd:
Consider using Shared Projects if you are using VS2013 update 2 (with Shared Project Reference Manager) or VS2015.

冷情妓 2024-09-23 21:23:59

mo 的答案和 Marcus 的评论的补充,如果您要链接内容项,则需要包含文件扩展名:

<ItemGroup>
  <Compile Include="any_abs_or_rel_path\**\*.*">
    <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Compile>
</ItemGroup>

One addition to the answer from mo. and the comment from Marcus, if you are linking content items you will need to include the file extension:

<ItemGroup>
  <Compile Include="any_abs_or_rel_path\**\*.*">
    <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Compile>
</ItemGroup>
打小就很酷 2024-09-23 21:23:59

关于原始查询中在 IDE 中出现链接文件夹的部分,有可能实现这一点,因此解决方案资源管理器中有一个文件夹,其中包含所有链接文件,而不是所有文件都出现在解决方案。要实现此目的,请添加以下内容:

  <ItemGroup>
    <Compile Include="..\anypath\**\*.*">
      <Link>MyData\A\%(RecursiveDir)%(FileName)%(Extension)</Link>
    </Compile>
  </ItemGroup>

这将包括解决方案资源管理器中名为 MyData 的新文件夹中链接目录中的所有文件。上面代码中的“A”可以任意命名,但必须存在才能显示文件夹。

Regarding the part of the original query to have a linked folder appear in the IDE, it is kind of possible to achieve this so there is a folder in the solution explorer with all linked files inside, instead of all the files appearing in the root of the solution. To achieve this, include the addition:

  <ItemGroup>
    <Compile Include="..\anypath\**\*.*">
      <Link>MyData\A\%(RecursiveDir)%(FileName)%(Extension)</Link>
    </Compile>
  </ItemGroup>

This will include all files from the linked directory in a new folder in the solution explorer called MyData. The 'A' in the code above can be called anything but must be there in order for the folder to appear.

蒲公英的约定 2024-09-23 21:23:59

如果您想添加一个文件夹作为参考并且不想编译它,请使用:

<Content Include="any_path\**\*.*">
  <Link>folder_in_B_project\%(RecursiveDir)%(FileName)%(Extension)</Link>
</Content>

If you want to add a folder as a reference and you don't want to compile it, use:

<Content Include="any_path\**\*.*">
  <Link>folder_in_B_project\%(RecursiveDir)%(FileName)%(Extension)</Link>
</Content>
很酷又爱笑 2024-09-23 21:23:59

即使有这么多解决方案,我还是花了一段时间才理解。在这里我将尝试稍微解释一下。

我需要链接到整个文件夹,所以我的最终结果是:

<ItemGroup>
    <Content Include="..\Gym.Management.Api\TestFolder\**\*.*">
        <Link>TestFolder\%(RecursiveDir)%(FileName)%(Extension)</Link>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
</ItemGroup>

其中:

  1. ..\Gym.Management.Api\TestFolder\ 表示包含我要链接的文件夹
  2. TestFolder 的其他项目的路径 标记中的 \ 是我当前项目中我想要链接它的最终(目标)文件夹

提示:
当您不确定如何获取正确的包含路径时,请在当前项目中右键单击项目 -> 单击添加 -> 现有项目 -> 从要链接的文件夹导航到这些文件之一 - >按旁边的下拉箭头而不是“添加” -> 单击“添加为链接”
此链接将插入到您的 .csproj 文件中,您可以从那里提取包含路径。

Even when there are so many solutions it took me a while to understand it. Here I will try to explain it a little bit more.

I needed link to the whole folder so my final result is:

<ItemGroup>
    <Content Include="..\Gym.Management.Api\TestFolder\**\*.*">
        <Link>TestFolder\%(RecursiveDir)%(FileName)%(Extension)</Link>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
</ItemGroup>

where:

  1. ..\Gym.Management.Api\TestFolder\ represents path to the other project containing the folder I want to link
  2. TestFolder\ in <link> tag is the final(destination) folder in my current project where I want to link it

TIP:
When you are not sure how to get the proper Include path then in your current project right click on project->click Add->Existing item->navigate to one of those files from folder you want to link-> instead of Add, press the dropdown arrow next to it->click Add as link.
This link is inserted in your .csproj file and from there you can extract the Include path.

数理化全能战士 2024-09-23 21:23:59

如果您正在寻找的是向当前工作区添加另一个文件夹以便于访问和访问,请执行以下操作:开发经验。

您只需单击文件 -> 即可完成此操作。 vscode 中的“将文件夹添加到工作区”选项。

If what you are looking for is to add another folder to your current workspace for easy access & development experience.

you can do this by just clicking file -> Add Folder to Workspace option in vscode.

樱花坊 2024-09-23 21:23:59

打破外壳并添加符号链接。

runas管理员然后

mklink /d LinkToDirectory DirectoryThatIsLinkedTo

BAM符号链接!

/d 指定目录链接。

开箱即用,可在 Vista 中使用。可以向后移植到 XP。

此处的文档: http://technet.microsoft.com /en-us/library/cc753194%28WS.10%29.aspx

对于那些不熟悉符号链接的人来说,它本质上是指向另一个文件或目录的指针。它对应用程序是透明的。磁盘上有一份副本,有多种解决方法。您还可以创建一个“硬链接”,它不是指向另一个地址的指针,而是 NTFS 中同一文件的实际文件 ID 条目。

注意:如评论中所述,这仅适用于您创建符号链接的计算机,而不适用于 git 等版本控制系统。

Bust out the shell and add a symbolic link.

runas Administrator then

mklink /d LinkToDirectory DirectoryThatIsLinkedTo

BAM symbolic link!

/d specifies directory link.

Works in Vista on up out of the box. Can be backported to XP.

Documentation here: http://technet.microsoft.com/en-us/library/cc753194%28WS.10%29.aspx

For those not familiar with symbolic links, it's essentially a pointer to another file or directory. It's transparent to applications. One copy on disk, several ways to address it. You can also make a "hard link" which is not a pointer to another address, but an actual file ID entry in NTFS for the same file.

NOTE: as stated in the comments, this would only work on the computer where you created the symlink and wouldn't work in a Version Control System like git.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文