How can I programmatically stop or start a website in IIS (6.0 and 7.0) using MsBuild?

By adding a reference to Microsoft.Web.Administration (which can be found inX:\Windows\System32\inetsrv, or your systems equivalent) you can achieve nice managed control of the situation with IIS7, as sampled below: namespace StackOverflow { using System; using System.Linq; using Microsoft.Web.Administration; class Program { static void Main(string[] args) { var server = new ServerManager(); var site = server.Sites.FirstOrDefault(s …

Read more

How to use command line msbuild to deploy VS2012 Web Site project without precompiling it?

For website project the publish process is not plumbed into the build process. For website project since there is no formal build process there was nothing for us to really extend. Note: the below contents requires to have VS 2012 (or VS2010 for that matter) and the Azure SDK on top of that. The features …

Read more

How to launch correct version of Msbuild

I found this question as my PATH variable did not contain a reference to MSBuild.exe. In case anyone else is having this issue, my resolution was to explictly register the environment variables for Visual Studio tools from the command prompt: “%VS100COMNTOOLS%”\\vsvars32.bat // VS2010 environment variables “%VS110COMNTOOLS%”\\vsvars32.bat // VS2012 environment variables “%VS120COMNTOOLS%”\\vsvars32.bat // VS2013 environment variables …

Read more

After Publish event in Visual Studio

UPDATE: seems like in VS 2019 and .NET 5 you can now use Publish target. <Target Name=”Test” AfterTargets=”Publish”> <Exec Command=”blablabla” /> </Target> Here’s my old answer that also works: MS has confirmed, that when publishing to file system they don’t have any target to launch after that. “We currently do not support executing custom targets …

Read more

In MSBuild is it possible to determine if I’m running in Visual Studio

The property value you should be using is BuildingInsideVisualStudio, when you are building inside of Visual Studio this property will be set to true. Since ProductVersion is declared in the project file you cannot use it because it will have the same value whether building inside of VS or via msbuild.exe. <PropertyGroup> <MyProp Condition=” ‘$(BuildingInsideVisualStudio)’ …

Read more

In MSBuild, can I use the String.Replace function on a MetaData item?

You can do this with a little bit of trickery: $([System.String]::Copy(‘%(Filename)’).Replace(‘config’,”)) Basically, we call the static method ‘Copy’ to create a new string (for some reason it doesn’t like it if you just try $(‘%(Filename)’.Replace(‘.config’,”))), then call the replace function on the string. The full text should look like this: <Target Name=”Build”> <Message Text=”@(Files->’$([System.String]::Copy(&quot;%(Filename)&quot;).Replace(&quot;.config&quot;,&quot;&quot;))’)” /> …

Read more

How to use MsBuild MsDeployPublish to target local file system?

As per my answer from Using MSBuild, how do I build an MVC4 solution from the command line (applying Web.config transformations in the process) and output to a folder? msbuild ProjectFile.csproj /p:Configuration=Release ^ /p:Platform=AnyCPU ^ /t:WebPublish ^ /p:WebPublishMethod=FileSystem ^ /p:DeleteExistingFiles=True ^ /p:publishUrl=c:\output Or if you are building the solution file: msbuild Solution.sln /p:Configuration=Release ^ /p:DeployOnBuild=True …

Read more