How to create MSBuild targets file to deploy files?

余生长醉 提交于 2019-12-11 00:49:31

问题


Given I have a post build process that generates files in \bin\out how can I use a MSBuild targets file to state that all files (recursively) in that directory should be published during web deploy?


回答1:


Let's split this in two parts:

First, build the web project:

<Target Name="BuildWeb">
    <MSBuild Projects="WebExtranet\WebExtranet.csproj"
             Properties="Configuration=$(Environment);DeployOnBuild=True;CreatePackageOnPublish=True;BaseIntermediateOutputPath=..\$(DistDir)\Web\" />
</Target>

Then use this to publish to the local IIS (you might need to adjust the msdeploy command to suit your needs)

<Target Name="DeployWeb">
    <ItemGroup>
        <PackageSourceDir Include='$(DistDir)\Web\$(Environment)\Package\WebExtranet.zip' />
    </ItemGroup>

    <Message Text="Package path: %(PackageSourceDir.FullPath)" />

    <Exec Command="&quot;c:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe&quot; -verb:sync -allowUntrusted -source:package=&quot;%(PackageSourceDir.FullPath)&quot; -setParam:'IIS Web Application Name'='My Web App' -dest:auto"/>
</Target>

Common pitfalls:

  • The msbuild version is important. I'm using V3.
  • You have to have the web application already created on IIS. Only need to do it once.

Note that the $(Environment) variable is the build configuration. I have several, but run the first target and check the folder structure created. Then adjust the script.



来源:https://stackoverflow.com/questions/12283701/how-to-create-msbuild-targets-file-to-deploy-files

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