【发布时间】:2014-02-05 02:45:40
【问题描述】:
我正在使用 Jenkins 和 MSBuild 构建我们的解决方案,并希望使用与我们的 Visual Studio 插件之一捆绑的命令行工具为我们生成 CSS 和 JavaScript。出于我希望显而易见的原因,我想使用 MSBuild 和 Visual Studio 项目文件来执行此操作,而不必维护单独的批处理文件。
我已经创建了一个单独的.targets 文件并且可以运行它,但是在自己获取文件时我很挣扎。我可以使用通配符从文件系统中获取文件,但我真正想做的是从项目文件本身中获取文件列表。
这是我们项目文件的简短版本 - 我删除了很多“默认”内容:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- I'll omit all the standard project bits and bobs for brevity -->
<ItemGroup>
<Content Include="css\scss\styles.scss">
<Compile>True</Compile>
<Minify>False</Compile>
<CompileStyle>Nested</CompileStyle>
<DebugInfo>False</DebugInfo>
</Content>
<Content Include="css\scss\_imported-1.scss">
<Compile>False</Compile>
<Minify>False</Compile>
<CompileStyle>Nested</CompileStyle>
<DebugInfo>False</DebugInfo>
</Content>
<Content Include="css\scss\_imported-2.scss">
<Compile>False</Compile>
<Minify>False</Compile>
<CompileStyle>Nested</CompileStyle>
<DebugInfo>False</DebugInfo>
</Content>
</ItemGroup>
<Import Project="$(SolutionDir)\.webcompile\WebCompile.targets" />
</Project>
WebCompile.targets 看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDependsOn>
$(BuildDependsOn);
WebCompile
</BuildDependsOn>
</PropertyGroup>
<ItemGroup>
<SassFiles Include="**/*.scss" />
</ItemGroup>
<Target Name="WebCompile">
<Message Text="SassFiles: @(SassFiles)" />
</Target>
</Project>
这将返回解决方案目录中所有匹配的*.scss 文件,但我真的很想只返回项目文件中已经列出的将<Compile> 子节点设置为True 的文件。
这可能吗?
【问题讨论】:
标签: visual-studio msbuild