且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Visual Studio 2012 - 如何将文件链接添加到同一项目中的文件

更新时间:2021-09-05 22:36:23

这是不可能的.

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.