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=""c:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -allowUntrusted -source:package="%(PackageSourceDir.FullPath)" -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.