visual-studio Visual Studio 项目中文件夹的“添加为链接”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3610845/
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
"Add as Link" for folders in Visual Studio projects
提问by kpozin
In Visual Studio, we can "Add as link" to add a link to a file in another project in the solution.
在 Visual Studio 中,我们可以通过“添加为链接”在解决方案中的另一个项目中添加指向文件的链接。
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?
有没有办法对整个文件夹执行此操作,以便项目 A 中的整个文件夹在项目 B 中可见,而无需手动链接到该文件夹中的新项目?
回答by mo.
回答by mt_serg
In VS2012 and later, you can drag a folder to another project with altkey pressed. It's just the same as adding each file as link manually but faster.
在 VS2012 及更高版本中,您可以按住alt键将文件夹拖到另一个项目中。这与手动添加每个文件作为链接相同,但速度更快。
upd: Consider using Shared Projectsif you are using VS2013 update 2 (with Shared Project Reference Manager) or VS2015.
回答by Chad
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:
莫的答案的一个补充。以及来自 Marcus 的评论,如果您要链接内容项,则需要包含文件扩展名:
<ItemGroup>
<Compile Include="any_abs_or_rel_path\**\*.*">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
</ItemGroup>
回答by Adam
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:
关于在 IDE 中出现链接文件夹的原始查询部分,有可能实现这一点,因此解决方案资源管理器中有一个文件夹,其中包含所有链接文件,而不是出现在根目录中的所有文件解决方案。为了实现这一点,包括添加:
<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.
这将包括解决方案资源管理器中名为 MyData 的新文件夹中链接目录中的所有文件。上面代码中的“A”可以称为任何名称,但必须存在才能显示文件夹。
回答by Neshta
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>
回答by John Vance
Bust out the shell and add a symbolic link.
打破外壳并添加符号链接。
runas Administrator then
runas 管理员然后
mklink /d LinkToDirectory DirectoryThatIsLinkedTo
BAM symbolic link!
BAM 符号链接!
/d specifies directory link.
/d 指定目录链接。
Works in Vista on up out of the box. Can be backported to XP.
可在 Vista 中开箱即用。可以向后移植到 XP。
Documentation here: http://technet.microsoft.com/en-us/library/cc753194%28WS.10%29.aspx
此处的文档: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.
对于那些不熟悉符号链接的人来说,它本质上是一个指向另一个文件或目录的指针。它对应用程序是透明的。磁盘上的一份副本,几种解决方法。您还可以创建一个“硬链接”,它不是指向另一个地址的指针,而是同一文件在 NTFS 中的实际文件 ID 条目。
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.
注意:如评论中所述,这仅适用于您创建符号链接的计算机,而不适用于 git 等版本控制系统。

