2017-06-20 32 views
0

我发现这样here.怎样的ItemGroup转换成的PropertyGroup在MSBUILD

了类似的问题,但这并不解决我的问题。我有这样

<ItemGroup> 
    <DocumentationSource Include="TestLibrary\TestLibrary.csproj;TestLibrary2\TestLibrary2.csproj;TestLibrary2\TestLibrary3.csproj" /> 
</ItemGroup> 

一个的ItemGroup我需要按此格式

<PropertyGroup> 
    <DocumentationSources> 
     <DocumentationSource sourceFile="TestLibrary\TestLibrary.csproj" /> 
     <DocumentationSource sourceFile="TestLibrary2\TestLibrary2.csproj" /> 
     <DocumentationSource sourceFile="TestLibrary2\TestLibrary3.csproj" /> 
    </DocumentationSources> 
</PropertyGroup> 

我使用沙塔文档构建生成文件变成这样的PropertyGroup。这需要我以PropertyGroup格式显示的文档源。但是在我的构建脚本中,我已经有了一个ItemGroup,它具有上述格式中提到的所有项目。

如何在此处使用该ItemGroup作为SandCastle的文档来源或如何将ItemGroup转换为以上格式的PropertyGroup?

其实我可以改变的ItemGroup到的PropertyGroup格式,但已经有一些逻辑动态形成这样

<_ProjectFilesPlatform Include="%(ProjectDefinitionsPlatform.Identity)"> 
     <_ProjectPath>$([System.String]::Copy(%(ProjectDefinitionsPlatform.Identity)).Replace(".","\"))</_ProjectPath> 
     </_ProjectFilesPlatform> 

[这是一个粗略的轮廓我给了这里。这个操作不是实际使用的]

我是这个MSBUILD脚本的新手。任何人都可以对此有所了解吗?

谢谢。

回答

1

您可以使用@()语法将项目转换为由换行符分隔的字符串。下面是一个例子项目文件(的MSBuild 15 .NET的核心测试):

<Project> 
    <ItemGroup> 
    <DocumentationSource Include="TestLibrary\TestLibrary.csproj;TestLibrary2\TestLibrary2.csproj;TestLibrary2\TestLibrary3.csproj" /> 
    </ItemGroup> 

    <PropertyGroup> 
    <DocumentationSources> 
     @(DocumentationSource->'&lt;DocumentationSource sourceFile="%(Identity)" /&gt;', ' 
     ') 
    </DocumentationSources> 
    </PropertyGroup> 

    <Target Name="Build"> 
    <Message Importance="high" Text="Value of DocumentationSources: $(DocumentationSources)" /> 
    </Target> 
</Project> 

将会产生以下的输出:

$ dotnet msbuild 
Microsoft (R) Build Engine version 15.3.378.6360 for .NET Core 
Copyright (C) Microsoft Corporation. All rights reserved. 

    Value of DocumentationSources: 
     <DocumentationSource sourceFile="TestLibrary/TestLibrary.csproj" /> 
     <DocumentationSource sourceFile="TestLibrary2/TestLibrary2.csproj" /> 
     <DocumentationSource sourceFile="TestLibrary2/TestLibrary3.csproj" /> 

这甚至允许您使用通配符为您的项目元素:

<DocumentationSource Include="**\*.csproj" /> 
+0

非常感谢你的男人。这是我正在寻找的。 – shanmugharaj

相关问题