为具有多个C#项目的解决方案编写MSBuild

为具有多个C#项目的解决方案编写MSBuild,msbuild,Msbuild,我对MSBuild很陌生。我正在尝试两种不同的解决方法。测试给了我错误,编译工作正常,但我甚至不确定它是否有任何作用 <?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration>Debug</Configuration&g

我对MSBuild很陌生。我正在尝试两种不同的解决方法。测试给了我错误,编译工作正常,但我甚至不确定它是否有任何作用

<?xml version="1.0" encoding="utf-8"?>

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<Configuration>Debug</Configuration>
<AssemblyName>MSBuildSample</AssemblyName>
<OutputPath>Output\</OutputPath>
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" />
<Reference Include="**\*.dll"/>
</ItemGroup>

<ItemGroup>
 <ProjectsToBuild Include="**\*proj" Exclude="$(MSBuildProjectFile)"/>
</ItemGroup>

<Target Name="Test">
<MakeDir Directories="$(OutputPath)"      Condition="!Exists('$(OutputPath)')" />
<Csc Sources="@(Compile)"  References="@(Reference)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
<Message Text="The output file is done"/>
</Target>

<Target Name="Clean">
<MSBuild Projects="@(ProjectsToBuild)" ContinueOnError="false" Targets="Clean"
        Properties="Configuration= $(Configuration)" />
</Target>

<Target Name="Compile" DependsOnTargets="Clean">
<MSBuild Projects="@(ProjectsToBuild)" ContinueOnError="false" Properties="Configuration=$(Configuration)">
  <Output ItemName="BuildOutput" TaskParameter="TargetOutputs"/>
</MSBuild>
</Target>

</Project>

调试
MSBuildSample
输出\

我走的路对吗?

您只需将解决方案文件作为项目传递给
MSBuild
任务:

<MSBuild Projects="MySolution.sln"  />


如果这不是你的情况,请让我知道

编辑:回复评论

来自MSDN:

此任务不仅可以处理项目文件,还可以处理解决方案文件

MSBuild
不创建解决方案文件。考虑到您有一个包含您提到的两个项目的解决方案文件,您可以只指定一个解决方案文件,并将所有包含的项目都指定为MSBuild

也许你需要这个:

谢谢您的帮助。这是作弊吗?Visual Studio是否创建解决方案文件?如果没有,那么我有:这是有效的,但我不确定它的作用。我现在该怎么办?谢谢你的帮助。抱歉,如果这些问题都很愚蠢,我一般都不熟悉MSBuild和Stackoverflow。除了建造,还必须做什么?关于清理或部署呢?如果您是导入标准Microsoft目标,它将为您提供更复杂的清理、部署工作,基本上看一下复制任务,想法是从$(OutDir)复制到自定义$(DeploymentDir)这是Silverlight。你知道这有什么不同吗?@Shazam:我没有使用Silverlight的经验,但我相信对于多个项目的单一解决方案也有相同的想法?
<MSBuild Projects="$(PathToSolutionFile)"  />