.net – Publish WCF Service (or ASP.NET Web Application) using command line

msbuildnet

I would like to simulate "Publish…" menu item from WCF Service project (or ASP.NET Web Application or…) context menu in Visual Studio 2008. I do not have a need to publish it to a running IIS instance, just to put the web content together with bin folder on some local dir. Is there any way to add it in post build events, or as a MSBuild task?

Best Answer

Here is the answer, thanks to this link: http://codingcockerel.co.uk/2008/05/18/how-to-publish-a-web-site-with-msbuild/ So, I have just modified the .csproj file of web application, and wrote this into AfterBuild target (that was already there):

<Target Name="BeforeBuild">
    <Message Text="##############Before build##################" Importance="high"/>
    <RemoveDir Directories="publish"
        ContinueOnError="true"/>
</Target>
<Target Name="AfterBuild">
    <Message Text="##############After build##################$(OutputFolder)" Importance="high"/>
    <MSBuild Projects="$(ProjectName).csproj"
           Targets="ResolveReferences;_CopyWebApplication"
           Properties="WebProjectOutputDir=publish\;OutDir=publish\bin\" />
</Target>