Created
July 10, 2016 08:51
-
-
Save lavn0/64da07946e2097ee1fe5b5bd845d15a1 to your computer and use it in GitHub Desktop.
Xmlの値を読み取るMSBuildタスクを定義するコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<UsingTask TaskName="XmlRead" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> | |
<ParameterGroup> | |
<XmlFileName ParameterType="System.String" Required="true" /> | |
<XPath ParameterType="System.String" Required="true" /> | |
<Result ParameterType="System.String" Output="true" /> | |
</ParameterGroup> | |
<Task> | |
<Reference Include="System" /> | |
<Reference Include="System.Xml" /> | |
<Reference Include="System.Xml.Linq" /> | |
<Using Namespace="System.Collections.Generic" /> | |
<Using Namespace="System.Xml.Linq" /> | |
<Using Namespace="System.Xml.XPath" /> | |
<Code Type="Fragment" Language="cs"><![CDATA[ | |
var xdoc = XDocument.Load(XmlFileName); | |
var nodes = (IEnumerable<object>)xdoc.XPathEvaluate(XPath); | |
var result = nodes.First() as XText; | |
Result = result.Value; | |
]]></Code> | |
</Task> | |
</UsingTask> | |
<!-- Sample Code | |
<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'"> | |
<XmlRead XmlFileName="sample.xml" XPath="/root/sub/content/text()"> | |
<Output TaskParameter="Result" PropertyName="contentValue" /> | |
</XmlRead> | |
<Message Text="contentValue ::$(contentValue)" Importance="high" /> | |
</Target> | |
--> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment