![](/img/trans.png)
[英]How to build a csproj file using .net 2.0 MSBuild programmatically?
[英]How to build the file using MSBuild
我创建了一个 C# 文件。 通常我们使用 Visual Studio IDE 构建它。 但我想使用 MSBuild 构建它。
我有一个.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-bin .cache.ttl.default=eternal -buildfile %BUILD_FILE%
您的 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 方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.