MSBuild:如何在链接的父目录中包含一堆文件?
MSBuild: How to include a bunch of files in the parent directory as linked?
我正在编写一个具有以下目录结构的 C# 项目:
LibFoo
|
---- LibFoo.Shared
| |
| ---- [a bunch of .cs files]
|
---- LibFoo.Uwp
| |
| ---- LibFoo.Uwp.csproj
|
---- LibFoo.Wpf
|
---- LibFoo.Wpf.csproj
我很想知道,是否可以包含共享目录中的 C# 文件,以便它们显示在 Visual Studio 的解决方案资源管理器中?我知道你可以通过为 <Compile>
标签设置 Link
属性 来做到这一点,但我不太确定当有可变数量的 .cs
项目中的文件。
澄清一下,这是我的 csproj 文件的相关部分:
<PropertyGroup>
<!-- Compile everything in this dir -->
<CompileRoot>..\LibFoo.Shared</CompileRoot>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CompileRoot)\**\*.cs">
<Link> <!--What goes here?--> </Link>
</Compile>
</ItemGroup>
感谢您的帮助!
编辑: 忘了说,它们包含在父目录中这一事实是相关的,因为这就是它们没有出现在 Visual Studio 中的原因。如果他们出现在 VS 中,我就不必做任何这些链接的事情了。
编辑 2: 按照 shamp00 的 建议,我尝试了这个:
<ItemGroup>
<Compile Include="$(CompileRoot)\**\*.cs">
<Link>$([MSBuild]::MakeRelative('$(CompileRoot)', '%(FullPath)'))</Link>
</Compile>
</ItemGroup>
不幸的是,虽然当我 运行 来自项目的 Message
任务时它似乎输出正常,但链接似乎在 Visual Studio.[=20 中被忽略了=]
编辑 3: 对于那些有兴趣重现这个问题的人,你可以从 GitHub repository:
git clone git@github.com:jamesqo/typed-xaml
cd typed-xaml
之后,你可以打开Visual Studio中的解决方案,自己看看效果。相关代码在this文件中。
像这样的东西应该可以工作:
<Target Name="Default">
<ItemGroup>
<Parent Include="..\LibFoo.Shared\**\*.cs"/>
<Compile Include="@(Parent)">
<Link>..\LibFoo.Shared\%(Parent.Filename).cs</Link>
</Compile>
</ItemGroup>
<Message Text="%(Compile.Identity) is linked to %(Compile.Link)"/>
</Target>
编辑
根据this answer,以下作品...
<Compile Include="..\LibFoo.Shared\**\*.cs">
<Link>.\thisDummyFolderNameDoesNotMatter</Link>
</Content>
编辑 2
我不确定如何让它与您的外部 common.props 文件一起使用,但是如果您将以下内容直接添加到 Typed.Xaml.Wpf.csproj.
<ItemGroup>
<Compile Include="..\Typed.Xaml\**\*.cs">
<Link>notimportant</Link>
</Compile>
</ItemGroup>
我正在编写一个具有以下目录结构的 C# 项目:
LibFoo
|
---- LibFoo.Shared
| |
| ---- [a bunch of .cs files]
|
---- LibFoo.Uwp
| |
| ---- LibFoo.Uwp.csproj
|
---- LibFoo.Wpf
|
---- LibFoo.Wpf.csproj
我很想知道,是否可以包含共享目录中的 C# 文件,以便它们显示在 Visual Studio 的解决方案资源管理器中?我知道你可以通过为 <Compile>
标签设置 Link
属性 来做到这一点,但我不太确定当有可变数量的 .cs
项目中的文件。
澄清一下,这是我的 csproj 文件的相关部分:
<PropertyGroup>
<!-- Compile everything in this dir -->
<CompileRoot>..\LibFoo.Shared</CompileRoot>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CompileRoot)\**\*.cs">
<Link> <!--What goes here?--> </Link>
</Compile>
</ItemGroup>
感谢您的帮助!
编辑: 忘了说,它们包含在父目录中这一事实是相关的,因为这就是它们没有出现在 Visual Studio 中的原因。如果他们出现在 VS 中,我就不必做任何这些链接的事情了。
编辑 2: 按照 shamp00 的 建议,我尝试了这个:
<ItemGroup>
<Compile Include="$(CompileRoot)\**\*.cs">
<Link>$([MSBuild]::MakeRelative('$(CompileRoot)', '%(FullPath)'))</Link>
</Compile>
</ItemGroup>
不幸的是,虽然当我 运行 来自项目的 Message
任务时它似乎输出正常,但链接似乎在 Visual Studio.[=20 中被忽略了=]
编辑 3: 对于那些有兴趣重现这个问题的人,你可以从 GitHub repository:
git clone git@github.com:jamesqo/typed-xaml
cd typed-xaml
之后,你可以打开Visual Studio中的解决方案,自己看看效果。相关代码在this文件中。
像这样的东西应该可以工作:
<Target Name="Default">
<ItemGroup>
<Parent Include="..\LibFoo.Shared\**\*.cs"/>
<Compile Include="@(Parent)">
<Link>..\LibFoo.Shared\%(Parent.Filename).cs</Link>
</Compile>
</ItemGroup>
<Message Text="%(Compile.Identity) is linked to %(Compile.Link)"/>
</Target>
编辑
根据this answer,以下作品...
<Compile Include="..\LibFoo.Shared\**\*.cs">
<Link>.\thisDummyFolderNameDoesNotMatter</Link>
</Content>
编辑 2
我不确定如何让它与您的外部 common.props 文件一起使用,但是如果您将以下内容直接添加到 Typed.Xaml.Wpf.csproj.
<ItemGroup>
<Compile Include="..\Typed.Xaml\**\*.cs">
<Link>notimportant</Link>
</Compile>
</ItemGroup>