Visual Studio 2012 - 如何将文件链接添加到同一项目中的文件 [英] Visual Studio 2012 - How to add a file link to a file in the same project

查看:74
本文介绍了Visual Studio 2012 - 如何将文件链接添加到同一项目中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用添加现有项目"对话框中的添加为链接"选项将另一个 Visual Studio 2012 项目中的文件添加到当前项目时.文件链接创建得很好,一切都很好.

When I add a file from another Visual Studio 2012 project to my current project by using the 'Add As Link' option from the 'Add Existing Item' dialog. The file link is nicely created and everything is fine.

当我对 相同 VS2012 项目(但位于另一个文件夹)中的现有文件重复相同的技巧时,不会创建链接.Visual Studio 只是忽略该操作.为什么这不可能?是否有解决方法,以便我可以将文件链接添加到同一项目中的文件?

When I repeat the same trick for an existing file in the same VS2012 project (but located in another folder) the link won't be created. Visual Studio just ignores the action. Why isn't this possible? Is there a workaround for this, so I can add file links to files in the same project?

背景信息:我想使用 NuGet 包及其更新机制,但 NuGet 只是将所有内容转储到我不想使用的文件夹结构(如脚本"和内容"文件夹)中.我使用libs"文件夹来存放外部内容.但是当我移动 NuGet 导入的文件时,它破坏了更新机制,所以我想创建文件链接(在 libs 文件夹下方)到位于脚本"文件夹等中的导入文件.

Background information: I want to use NuGet packages and its update mechanism, but NuGet just dumps everything in a folder structure (like the 'Scripts' and 'Content' folders), which I don't want to use. I use a 'libs' folder for external stuff. But when I move the NuGet imported files, it breaks the update mechanism, so I want to create file links (below the libs folder) to the imported files located in the 'Scripts' folder etc.

我已经尝试手动编辑 .csproj 文件,但链接定义仍然被忽略.我能想到的唯一解决方案是为 NuGet 包创建另一个项目,并在我的另一个项目中添加指向这些导入文件的链接,但这在我看来有点矫枉过正.

I already tried to manually edit the .csproj file, but than the link definitions are still ignored. The only solution I can think of is by creating another project for just the NuGet packages and add links to those imported files in my other project, but that seems to me as a bit of overkill.

推荐答案

这是不可能的.

csproj 文件只是一个 msbuild 文件,告诉构建过程哪些文件和引用构成了项目,以及在构建等方面要做什么.

The csproj file is simply an msbuild file, telling the build process what files and references make up the project and what to do in terms of build etc.

如果您查看 csproj 文件的组合方式,您会注意到有 ItemGroup 元素.这些 ItemGroup 元素的功能之一是将文件组合在一起.在文件组"中,每个项目(无论标记为 Compile 或 None 或其他)都指的是具有 Include 属性的文件,例如包括=文件名.ext".当您向解决方案添加文件时,它会创建这些元素之一,并将 Include 属性适当地设置为文件相对于项目的路径.但在此之前,它会检查项目中是否已经存在具有匹配路径的文件,如果存在则忽略它.

If you look at the way the csproj file is put together, you'll notice that there are ItemGroup elements. One of the functions of these ItemGroup elements is to group together files. In a "file group", each item (whether marked as Compile or None or whatever) refers to a file with the Include attribute e.g. Include="filename.ext". When you add a file to the solution, it will create one of these elements with the Include attribute appropriately set to the path of the file relative to the project. Before it does that though, it checks to see whether a file with the matching path is already in the project, and ignores it if it is.

所以你看,你想要做的是添加一个重复的文件,而 VS 不允许这样做.

So you see, what you're trying to do is add a duplicate file, and VS is not allowing that.

--编辑--

现在,至于解决方法.如果您要使用符号链接,则可以这样做.在命令窗口中,键入以下命令:

Now, as for a work-around. If you were to use a symlink, this can be done. In the command window, type the following command:

mklink Link Target

其中 Link 指定新的符号链接名称,Target 指定新链接引用的路径(相对或绝对).

where Link specifies the new symbolic link name and Target specifies the path (relative or absolute) that the new link refers to.

然后您应该能够根据需要将该文件添加到您的项目中.

You should then be able to add the file to your project as required.

这篇关于Visual Studio 2012 - 如何将文件链接添加到同一项目中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆