如何使用msbuild构建文件

时间:2014-06-19 07:00:05

标签: c# batch-file msbuild

我创建了c#文件。通常我们使用VS IDE构建它。但我想用ms-build构建它。

我有一个.bat和.xml文件。我与.xml文件有什么关系才能成功运行.cs文件。

我的.xml文件

<property environment="env" />
<property name="tools.dir" location="${env.TOOLS_DIR}"/>

<target name="Buildproject" >
<echo message="I am building project"/>
</target>   

<target name="runtests" depends="Buildproject" description="This is my first ant target">
<echo message="Running tests"/>
</target>

<target name="publish" depends="runtests">
<echo message="Publish artifact"/>
</target>

我的.bat文件

  

SET WORKSPACE =%~dp0 SET TOOLS_DIR = buildtools SET   BUILD_FILE = sample_build.xml @echo off echo WORKSPACE:%WORKSPACE%echo   TOOLS_DIR:%TOOLS_DIR%echo BUILD_FILE:%BUILD_FILE%   %TOOLS_DIR%/ apache-ant / bin / ant -Divy.cache.ttl.default =永恒   -buildfile%BUILD_FILE%

1 个答案:

答案 0 :(得分:0)

你的xml文件不对。它看起来像是一个nant文件或其他一些规范。

这是您最基本的.proj(msbuild定义)文件。

将此(与.sln文件位于同一目录中)保存为“MyMsbuildDef.proj”

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
    <PropertyGroup>
        <!-- Always declare some kind of "base directory" and then work off of that in the majority of cases  -->
        <WorkingCheckout>.</WorkingCheckout>
    </PropertyGroup>

    <Target Name="AllTargetsWrapped">
        <CallTarget Targets="BuildItUp" />
    </Target>


    <Target Name="BuildItUp" >
        <MSBuild Projects="$(WorkingCheckout)\MySolution_Or_MyProject_File.sln" Targets="Build" Properties="Configuration=$(Configuration)">
            <Output TaskParameter="TargetOutputs" ItemName="TargetOutputsItemName"/>
        </MSBuild>
        <Message Text="BuildItUp completed" />
    </Target>

</Project>

显然,将“MySolution_Or_MyProject_File.sln”更改为.sln名称。

现在创建一个名为“MyMsbuildCallIt.bat”的.bat文件并将其放入:

REM set __msBuildDir=%WINDIR%\Microsoft.NET\Framework\v2.0.50727
REM set __msBuildDir=%WINDIR%\Microsoft.NET\Framework\v3.5
set __msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319

call "%__msBuildDir%\msbuild.exe" /target:AllTargetsWrapped "MyMsbuildDef.proj" /p:Configuration=Debug;FavoriteFood=Popeyes /l:FileLogger,Microsoft.Build.Engine;logfile=MyMsbuildDef_Debug.log
call "%__msBuildDir%\msbuild.exe" /target:AllTargetsWrapped "MyMsbuildDef.proj" /p:Configuration=Release;FavoriteFood=Popeyes /l:FileLogger,Microsoft.Build.Engine;logfile=MyMsbuildDef_Release.log


set __msBuildDir=

运行.bat文件。

这是你最基本的msbuild场景。

相关问题