C# MSBuild:如何将一组文件作为链接包含在父目录中?
我正在写一个C#项目,其中我有以下目录结构:C# MSBuild:如何将一组文件作为链接包含在父目录中?,c#,.net,msbuild,conditional-compilation,C#,.net,Msbuild,Conditional Compilation,我正在写一个C#项目,其中我有以下目录结构: LibFoo | ---- LibFoo.Shared | | | ---- [a bunch of .cs files] | ---- LibFoo.Uwp | | | ---- LibFoo.Uwp.csproj | ---- LibFoo.Wpf | ---- LibFoo.Wpf.csproj 我很想知道,是否可以将共享目录中的C#文件包括在内,以便它们显示在VisualStudio的解决方案资源
LibFoo
|
---- LibFoo.Shared
| |
| ---- [a bunch of .cs files]
|
---- LibFoo.Uwp
| |
| ---- LibFoo.Uwp.csproj
|
---- LibFoo.Wpf
|
---- LibFoo.Wpf.csproj
我很想知道,是否可以将共享目录中的C#文件包括在内,以便它们显示在VisualStudio的解决方案资源管理器中?我知道您可以通过为
标记设置链接属性来实现这一点,但我不太确定在项目中存在数量可变的.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>
之后,您可以在VisualStudio中打开解决方案并亲自查看效果。相关代码在文件中。类似的代码应该可以工作:
<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>
..\LibFoo.Shared\%(Parent.Filename).cs
编辑
据介绍,以下作品
<Compile Include="..\LibFoo.Shared\**\*.cs">
<Link>.\thisDummyFolderNameDoesNotMatter</Link>
</Content>
.\ThisDummyFolderName不符合要求
编辑2
我不知道如何让它与外部common.props文件一起工作,但是如果您将以下内容直接添加到Typed.Xaml.Wpf.csproj,它就会工作
不重要
谢谢!不幸的是,虽然消息似乎显示正确,但它们似乎没有显示在Visual Studio中。不幸的是,它仍然不起作用…:(如果您对获取复制感兴趣,您可以自己尝试。相关代码在文件中。它在csproj文件中工作。放弃尝试使其与。
<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>
<Compile Include="..\LibFoo.Shared\**\*.cs">
<Link>.\thisDummyFolderNameDoesNotMatter</Link>
</Content>
<ItemGroup>
<Compile Include="..\Typed.Xaml\**\*.cs">
<Link>notimportant</Link>
</Compile>
</ItemGroup>