Visual Studio解决方案中的公共文件

时间:2022-02-20 22:49:06

Many times I have seen Visual Studio solutions which have multiple projects that share source files. These common source files are usually out in a common directory and in the solution explorer their icon shows up with a link arrow in the bottom left.

很多时候我见过Visual Studio解决方案,它有多个共享源文件的项目。这些常见的源文件通常位于公共目录中,而在解决方案资源管理器中,它们的图标会在左下方显示一个链接箭头。

However, any time I try to add a source file to the project that is outside of that project's main directory, it just automatically copies it into the directory so that I no longer have a shared copy.

但是,每当我尝试将源文件添加到该项目主目录之外的项目时,它只会自动将其复制到目录中,以便我不再拥有共享副本。

I found that I can get around this by manually opening the project file in a text editor and modifying the path to something like "../../../Common/Source.cs" but this is more of a hack then I would like.

我发现我可以通过在文本编辑器中手动打开项目文件并修改类似“../../../Common/Source.cs”的路径来解决这个问题,但这更像是一个黑客然后我想。

Is there a setting or something I can change that will allow me to do this from within the IDE?

是否有一个设置或我可以更改的内容,这将允许我在IDE中执行此操作?

2 个解决方案

#1


22  

Right click on a project, select Add->Existing Item->Add as link (press on small arrow on Add button)

右键单击项目,选择Add-> Existing Item-> Add as link(按Add按钮上的小箭头)

#2


3  

Thanks @aku!

I knew this could be done, but I didn't know how to do this from Visual Studio. It shows up as a shortcut to the file and the csproj file generates the resulting XML like this:

我知道这可以做到,但我不知道如何从Visual Studio中做到这一点。它显示为文件的快捷方式,csproj文件生成结果XML,如下所示:

<Compile Include="..\CommonAssemblyInfo.cs">
  <Link>CommonAssemblyInfo.cs</Link>
</Compile>

I've seen this technique commonly used for common AssemblyInfo files to keep a consistent version.

我已经看到这种常用于常见AssemblyInfo文件的技术,以保持一致的版本。

#1


22  

Right click on a project, select Add->Existing Item->Add as link (press on small arrow on Add button)

右键单击项目,选择Add-> Existing Item-> Add as link(按Add按钮上的小箭头)

#2


3  

Thanks @aku!

I knew this could be done, but I didn't know how to do this from Visual Studio. It shows up as a shortcut to the file and the csproj file generates the resulting XML like this:

我知道这可以做到,但我不知道如何从Visual Studio中做到这一点。它显示为文件的快捷方式,csproj文件生成结果XML,如下所示:

<Compile Include="..\CommonAssemblyInfo.cs">
  <Link>CommonAssemblyInfo.cs</Link>
</Compile>

I've seen this technique commonly used for common AssemblyInfo files to keep a consistent version.

我已经看到这种常用于常见AssemblyInfo文件的技术,以保持一致的版本。