MSBuild - How to build a .NET solution file (in an XML task script) from pre-written command line commands

…衆ロ難τιáo~ 提交于 2019-11-29 21:04:06

Use the MSBuild task to build the solution passing the properties you need.

<?xml version="1.0" encoding="utf-8"?>
<Project
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
    ToolsVersion="4.0"
    DefaultTargets="Build">

    <PropertyGroup>
        <OutputDir>c:\TESTMSBUILDOUTPUT</OutputDir>
    </PropertyGroup>

    <ItemGroup>
        <ProjectToBuild Include="MySecretApplication.sln">
            <Properties>OutputPath=$(OutputDir);Configuration=Release</Properties>
        </ProjectToBuild>
    </ItemGroup>

    <Target Name="Build">
        <MSBuild Projects="@(ProjectToBuild)"/>
    </Target>

</Project>

Here is my final MSBuild script:

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

<PropertyGroup>
    <OutputDir>C:\TESTMSBUILDOUTPUT</OutputDir>
</PropertyGroup>

<ItemGroup>
    <ProjectToBuild Include="MyTopSecretApplication.sln" >
        <Properties>OutputPath=$(OutputDir);Configuration=MSBuildRelease;Platform=x86</Properties>
    </ProjectToBuild>
</ItemGroup>

<Target Name="Build">
    <MSBuild Projects="@(ProjectToBuild)"/>
</Target>

As you can see, the main difference from Brian Walker's answer is the "Configuration" setting. Here it is set to "MSBuildRelease" instead of "Release", which I customized from within the .NET IDE. Follow the steps Brian suggested (right-click on the solution node and choose Configuration Manager in Visual Studio, add "NEW" configuration and remove/uncheck projects you want excluded.)

I have since uploaded this to my TEAMCITY server, and have automated my .NET build process with your help. Thanks so much to Brian Walker (a fellow Texan)...I'll buy you a beer!! CHEERS!!

I know this isn't a direct answer to your question, but why not just use the built in Visual Studio build runner and pick up the compiled output from the appropriate /obj path and save it as a build artefact? If you're effectively not doing anything beyond a simple compile against a specified build configuration then there's not much value added by having a dedicated build file and using build artefacts can make a life a whole lot easier (use them in other builds, download them easily, etc).

Try the configuration described here if this isn't making sense: http://www.troyhunt.com/2010/11/you-deploying-it-wrong-teamcity_25.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!