使用MSBuild从网站构建中排除文件夹 [英] Exclude folder from website build using MSBuild
问题描述
我们使用MSBuild通过CruiseControl构建我们的解决方案.作为解决方案的一部分,我们有多个程序集和一个网站.通过VS2008构建,构建成功.但是,在生成框上,我们收到以下错误.
We use MSBuild to build our solutions through CruiseControl. We have several assemblies and a website as part of the solution. Building through VS2008 the build is successful. However on the build box we get the following error.
ASPNETCOMPILER (,):
errorASPCONFIG: The CodeDom provider type "Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be located.
这样做的原因是,在网站的scripts文件夹中,我们有几个扩展名为.java的文件.我们不希望构建这些文件.确实,在构建的scripts文件夹中我们不需要任何东西.
The reason for this is that in the scripts folder of the website we have a couple files with the .java extension. We don't want these files built. And really we don't need anything in the scripts folder built.
是否可以从网站项目中排除构建文件夹或扩展名的方法?还是让MSBuild遵循VS2008用来决定编译内容的相同规则?
Is there a way to exclude a folder or an extension from being built within a website project? Or tell MSBuild to follow the same rules VS2008 is using to decide what to compile?
推荐答案
您可以使用在MSDN上的简要介绍).
例如,如果您有这样定义的项目:
You can remove whole folders with Remove attribute of Item element (brief introduction on MSDN).
For example, if you have items defined like this:
<ItemGroup>
...
<Compile Include="Tests\Test1.cs" />
<Compile Include="Tests\SubTests\SubTest1.cs" />
...
</ItemGroup>
,并且要从"Tests"文件夹中排除所有类,可以在项目结束时定义一个任务:
and you want to exclude all classes from "Tests" folder, you can define a task at the end of your project:
...
<PropertyGroup>
<CoreCompileDependsOn>$(CoreCompileDependsOn);ExcludeTestsFolder</CoreCompileDependsOn>
</PropertyGroup>
<Target Name="ExcludeTestsFolder">
<ItemGroup>
<Compile Remove="Tests\**\*.cs" />
</ItemGroup>
</Target>
</Project>
在外部文件中定义此类任务并使用在另一个线程中进行了详尽的解释).
It's also a good idea to define such a task in an external file and import it with Import element (thorough explanation in another thread).
这篇关于使用MSBuild从网站构建中排除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!