Question

I have several XSLTs used in my ASP.NET web application. I want these files to be compiled to dll whenever I build the project. Currently, I'm compiling the xslts manually by invoking xsltc.exe from vs2010 tools command prompt.

How can I add msbuild task for xsltc.exe so that it will generate assembly whenevr i build my project?

I'm using .NET 4.0.

Was it helpful?

Solution 2

<PropertyGroup>
     <WinSDK>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin</WinSDK>
</PropertyGroup>    
<Target Name="Build">
    <Exec Command="%22$(WinSDK)\xsltc.exe%22 /out:$(OutputPath)\_PublishedWebsites\xyzapp\bin\Xslts.dll /class:ABC %22$(MSBuildProjectDirectory)\xyzapp\a.xslt%22 /class:DEF %22$(MSBuildProjectDirectory)\xyzapp\b.xslt%22 /class:GHI %22$(MSBuildProjectDirectory)\xyzapp\c.xslt%22"/>
</Target>

OTHER TIPS

That works but doesn't really wrap the tool in a MSBuild friendly way. I came up with this (which was good enough to get by).

<!-- The Transform File Names... -->
<ItemGroup>
  <XsltcTransform Include="Transform1.xslt">
    <!-- And the generated .Net Class name. -->
    <Class>Transform1Class</Class>
  </XsltcTransform>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- Sadly using $(OutDir) MUST come after the Import of CSharp.targets -->
<PropertyGroup>
  <XSLTCOutputDll>$(OutDir)xslts.dll</XSLTCOutputDll>
</PropertyGroup>
<Target Name="FindXSLTC">
  <PropertyGroup>
    <XSLTC>"$(TargetFrameworkSDKToolsDirectory)xsltc.exe"</XSLTC>
  </PropertyGroup>
</Target>
<Target Name="XSLTC" Inputs="@(XsltcTransform)" Outputs="$(XSLTCOutputDll)"   DependsOnTargets="FindXSLTC">
  <Exec Command="$(XSLTC) /out:&quot;$(XSLTCOutputDll)&quot; @(XsltcTransform -> ' /class:%(Class) %(FullPath) ')" />
</Target>
<Target Name="BeforeResolveReferences" DependsOnTargets="XSLTC">
</Target>

These targets will let you compile multiple transforms into one DLL. Running XSLTC before "BeforeResolveRefereneces" is necessary so that you can have an assembly reference to the generated DLL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top