环顾四周后,我无法找到这个问题的简单答案。MSBuild:添加额外的文件进行编译,而不改变项目文件
我想创建一个MSBuild文件,以便我可以在Visual Studio 2010 express中轻松使用SpecFlow和NUnit。
下面的文件不完整,这仅仅是一个概念的证明,它需要更通用。
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDependsOn>
BuildSolution;
SpecFlow;
BuildProject;
NUnit;
</BuildDependsOn>
</PropertyGroup>
<PropertyGroup>
<Solution>C:\Users\Craig\Documents\My Dropbox\Cells\Cells.sln</Solution>
<CSProject>C:\Users\Craig\Documents\My Dropbox\Cells\Configuration\Configuration.csproj</CSProject>
<DLL>C:\Users\Craig\Documents\My Dropbox\Cells\Configuration\bin\Debug\Configuration.dll</DLL>
<CSFile>C:\Users\Craig\Documents\My Dropbox\Cells\Configuration\SpecFlowFeature1.feature.cs</CSFile>
</PropertyGroup>
<Target Name="Build" DependsOnTargets="$(BuildDependsOn)">
<Message Text="Build Started" Importance="high" />
<Message Text="Build Ended" Importance="high" />
</Target>
<Target Name="BuildSolution">
<Message Text="BuildSolution Started" Importance="high" />
<MSBuild Projects="$(Solution)" Properties="Configuration=Debug" />
<Message Text="BuildSolution Ended" Importance="high" />
</Target>
<Target Name="SpecFlow">
<Message Text="SpecFlow Started" Importance="high" />
<Exec Command='SpecFlow generateall "$(CSProject)"' />
<Message Text="SpecFlow Ended" Importance="high" />
</Target>
<Target Name="BuildProject">
<Message Text="BuildProject Started" Importance="high" />
<MSBuild Projects="$(CSProject)" Properties="Configuration=Debug" />
<Message Text="BuildProject Ended" Importance="high" />
</Target>
<Target Name="NUnit">
<Message Text="NUnit Started" Importance="high" />
<Exec Command='NUnit /run "$(DLL)"' />
<Message Text="NUnit Ended" Importance="high" />
</Target>
</Project>
SpecFlow任务查找.csproj文件并创建一个SpecFlowFeature1.feature.cs。 构建.csproj时需要包含此文件,以便NUnit可以使用它。
我知道我可以修改(直接或在副本上).csproj文件以包含生成的文件,但我宁愿避免这种情况。
我的问题是:有没有办法使用MSBuild任务来建立项目文件,并告诉它包括一个额外的文件包含在构建?
谢谢。
我阅读了您的博客文章,并遵循了所有步骤,但它对我无效。作为一个例子,我使用Tekpub MVC初学者网站,它不起作用。我得到的错误是: “C:\ WebTest \ VS2010ExpressSpecFlow.xml”(默认目标)(1) - > (AddSpecFlowCSFilesToProject target) - > C:\ WebTest \ VS2010ExpressSpecFlow.xml(86,5):error : 你调用的对象是空的。 – WVDominick 2010-06-21 14:33:58
+1需要时间来做到这一点。 – WVDominick 2010-06-21 14:34:30
谢谢你的去处,让人们碰到它就是我需要的。我会在有空的时候尽快看看......大概是这个周末。 – 2010-06-24 09:19:06