0

是否可以在构建期间或在构建前事件或构建后事件中调用 MSbuild publish?我正在尝试从解决方案中发布两个 Web 项目。我正在使用文件系统发布。这里的要求是,构建解决方案应该负责发布这两个 Web 项目。有人可以建议吗?

4

1 回答 1

0

我不会在构建后事件中放置太多部署逻辑。它变得“脆弱”。

创建一个单独的 .msbuild 文件,并在其中执行“额外”逻辑,而不是过多地使用 .csproj 文件。

下面是一个基本的例子。将下面的 xml 放在名为“MyBuildAndDeploy.msbuild”的文件中,将其放在与 .sln(或 .csproj)文件相同的文件夹中,然后从命令行使用 msbuild.exe“MyBuildAndDeploy.msbuild”。

因此,下面是构建主要解决方案然后将文件复制到某处的基本示例。

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


    <PropertyGroup>
        <!-- Always declare some kind of "base directory" and then work off of that in the majority of cases  -->
        <WorkingCheckout>.</WorkingCheckout>
        <BuildResultsRootFolder>$(WorkingCheckout)\..\BuildResults</BuildResultsRootFolder>
    </PropertyGroup>



    <Target Name="AllTargetsWrapper">

        <CallTarget Targets="BuildSolution" />
        <CallTarget Targets="CopyBuildOutputFiles" />

    </Target>


    <Target Name="BuildSolution">

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

    </Target>   


    <Target Name="CopyBuildOutputFiles">


        <MakeDir Directories="$(BuildResultsRootFolder)\$(Configuration)" Condition="!Exists('$(BuildResultsRootFolder)\$(Configuration)\')"/>  

        <ItemGroup>
            <BuildOutputFilesExcludeFiles Include="$(WorkingCheckout)\**\*.doesnotexist" />
            <BuildOutputFilesIncludeFiles Include="$(WorkingCheckout)\**\*.dll" Exclude="@(BuildOutputFilesExcludeFiles)" />    
            <BuildOutputFilesIncludeFiles Include="$(WorkingCheckout)\**\*.exe" Exclude="@(BuildOutputFilesExcludeFiles)" />    
            <BuildOutputFilesIncludeFiles Include="$(WorkingCheckout)\**\*.config" Exclude="@(BuildOutputFilesExcludeFiles)" />
            <BuildOutputFilesIncludeFiles Include="$(WorkingCheckout)\**\*.pdb" Exclude="@(BuildOutputFilesExcludeFiles)" />
        </ItemGroup>  

        <Copy SourceFiles="@(BuildOutputFilesIncludeFiles)" 
            DestinationFolder="$(BuildResultsRootFolder)\$(Configuration)\"/>

    </Target>


</Project>
于 2013-03-18T14:06:22.163 回答