Visual Studio 链接文件目录结构

发布于 2024-09-05 11:32:14 字数 746 浏览 9 评论 0原文

我有一个项目的两个版本。一种用于 Silverlight,另一种用于 .NET。 SL 项目拥有绝大多数代码库。我想将 SL 项目中的所有文件作为链接文件全局添加到 .NET 版本中。我已经成功地在 .NET 版本的 csproj 文件中做到了这一点:

<Compile Include="..\MyProj.Common.SL\**\*.cs" Exclude="..\MyProj.Common.SL\Properties\**">

不幸的是,这将所有文件都添加到了我的项目的根目录中...所以我最终得到了一个长长的不可读的链接文件列表.NET 项目。我真的真的不想手动维护整个重复的目录结构并处理目录名更改和文件名更改等等。

那么,有没有办法让Visual Studio在上面以通配符方式添加链接文件时保留目录结构呢?或者至少有一种方法可以将所有链接的文件分组到 .NET 项目中的一个目录下,例如 MyProj.Common.SL.Links?

我最接近的方法是在 标记下设置 false ,这可以有效地删除一长串不可读的列表300 多个文件......但不幸的是,这搞砸了 Resharper,它不再将这些文件视为有效,并且它在所有引用 .NET 项目的项目上变得疯狂。如果我能找到一种方法让 Resharper 不会变得一团糟,那也是一个可以接受的解决方案......

有什么建议吗?

谢谢。

I have two versions of a project. One for Silverlight and one for .NET. The SL project has the vast majority of the code base in it. I want to globally add all files from the SL project into the .NET version as linked files. I've managed to do so successfully like this in the csproj file for the .NET version:

<Compile Include="..\MyProj.Common.SL\**\*.cs" Exclude="..\MyProj.Common.SL\Properties\**">

Unfortunately, this adds all the files right to the root of my project... so I end up with a long unreadable list of linked files in the .NET project. I really really really don't want to have to maintain an entire duplicate directory structure by hand and deal with directory name changes and file name changes and whatnot.

So, is there any way to have Visual Studio preserve the directory structure when adding linked files in the wildcard manner above? Or is there at least a way of making it group all the linked files together under a directory in the .NET project like MyProj.Common.SL.Links?

The very closest I've come is to set the <Visible>false</Visible> under the <Compile> tag, which effectively removes the long unreadable list of 300+ files....but unfortunately this screws up Resharper, which no longer sees those files as valid and it goes crazy on all the projects that reference the .NET project. If I could figure out a way of making Resharper not get all messed up, that would be an acceptable solution too...

Any suggestions?

Thanks.

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

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

发布评论

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

评论(2

峩卟喜欢 2024-09-12 11:32:14

我想我找到了一种让它工作的方法:

<Compile Include="..\MyProj.Common.SL\**\*.cs" Exclude="..\MyProj.Common.SL\Properties\**">
  <Link>MyProj.Common.SL.LinkedFiles\MyProj.Common.SL.LinkedFiles</Link>
</Compile>

它将创建一个 MyProj.Common.SL.LinkedFiles 文件夹并将所有链接文件分组到该文件夹​​下。

I think I found a way of getting this to work:

<Compile Include="..\MyProj.Common.SL\**\*.cs" Exclude="..\MyProj.Common.SL\Properties\**">
  <Link>MyProj.Common.SL.LinkedFiles\MyProj.Common.SL.LinkedFiles</Link>
</Compile>

It will create a MyProj.Common.SL.LinkedFiles folder and group all the linked files under that folder.

双手揣兜 2024-09-12 11:32:14

我想我会这样做:

  • 复制现有项目的 项,其中可能有例如 Include="foo.cs"Include="Folder \bar.cs"
  • 将它们粘贴到新项目中
  • 搜索并替换 $1

我不知道我的正则表达式搜索和替换语法是否完全正确,但重点是,您已经有了一个好的项目,您应该能够剪切、粘贴、正则表达式替换它以获得相同的文件集,仅从不同的文件夹引用,并且具有相同的目录结构。

此时您仍然需要维护两个 .csproj,但这也很容易修复。现在获取这个新的编译项列表,并将其放入名为“Common.csproj”的文件中,该文件仅包含具有这些编译项的属性组,然后将两个项目 并且不包含任何自己的 Compile 项。

基本上,只需进行一些手工劳动来重构 .csproj 文件以进行一次共享,然后我想您就可以了。我不确定这是否是解锁您的“最简单”方法,但我认为这听起来大约像您可能想要的“理想”结构。

I think I would do this:

  • Copy the existing project's <Compile> items, which presumably have e.g. Include="foo.cs" and Include="Folder\bar.cs"
  • Paste them into the new project
  • Search and replace <Compile Include="(.*?)" /> with <Compile Include="..\Other\$1" ><Link>$1</Link></Compile>

I don't know if I got the regular expression search and replace syntax exactly right, but the point is, you already have a good project, you should be able to cut, paste, regex-replace it to get the same set of files, only referenced from a different folder, and with the same directory structure.

You'll still have two .csproj's to maintain at this point, but this is also easily fixed. Now take this new list of compile items, and put it in a file named e.g. "Common.csproj" that just contains the property group with those compile items, and then have both projects <Import Include="..\Common.csproj" /> and not include any Compile items of their own.

Basically, a little manual labor to refactor the .csproj file for sharing once, and then I think you'll be set. I am not sure if this is the 'easiest' way to unblock you, but I think this sounds approximately like what you may want for an 'ideal' structure.

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