35

For normal (say Windows Forms) C# applications, to execute commands after a successful build I would use the Build Events->Post-build event command line in Project Properties.

I have a Web Site project which I "Publish", using the "Publish..." command in the context menu in the solution explorer.

Is there a way to run commands after the successful publish and if so how is it done? (eg a Post-Publish event command line field)

Visual Studio 2008, ASP .Net Web site project, C#.

Russell
  • 17,481
  • 23
  • 81
  • 125

1 Answers1

29

Update: Since Publish Web does not apply to folder-based web site projects, this answer assumes you are asking about a Web Application project.

You can't do this from inside the VS IDE. However, you can edit your project file in Notepad or your favorite XML editor and add a new target at the end of the file called AfterPublish.

You might want to read a bit more on MSBuild if you are not sure what you can do in this target.

You can find more details on extending the build process in VS at MSDN - HowTo: Extend the Visual Studio Build Process.

Franci Penov
  • 74,861
  • 18
  • 132
  • 169
  • Thanks, I feared that it would not be possible inside the IDE. This is a fine solution as our CI uses msbuild scripts. I was hoping we could do it inside Visual studio as well. What I might do is create a new msbuild script, then create an "External Tools" command to run that build script instead of doing a visual studio "publish." Would prefer not to modify the proj file if possible. Thanks for your help and quick response! – Russell Sep 01 '09 at 05:10
  • 1
    I voted answer down because I don't understand how this can be an accepted answer. A Web Site does not have a project file. Please help me and others understand by clarifying the answer or providing a comment of why this answer was accepted. – AMissico Oct 28 '09 at 23:30
  • 2
    It's just mixed terminology. You are right - folder based web site projects don't have a project file. However, there's also no Publish command for such projest. Web application projects on the other hand do have a project file and Publish Web command applies to them. My assumption was that the question refers to a web app vs. web site. Since my answer was accepted, I would venture to guess that my assumption was correct. That does not excused me from using the right terminology, of course. – Franci Penov Oct 29 '09 at 01:10
  • @Franci I was looking for this in the context of a web site project. It does have a publish, but no project file, so that's not quite right. – Ian Grainger Aug 01 '11 at 07:57
  • @Ian Grainger - It's been ~2 years since my answer. VS might have changed since then... :-) – Franci Penov Aug 01 '11 at 16:27
  • @Sam.Rueby I have no idea. I haven't touched Azure (or VS for that matter) in about a year and a half. :-( – Franci Penov Mar 26 '12 at 20:35
  • Its 2019, and web projects still have a project file. -- Hasn't gone away. -- Anyway, you should probably not be overriding the `AfterPublish` target and instead you should create a new target with a unique name that has an `AfterTargets="AfterPublish"` attribute. (This has always been the case; because if you have targets with the same name they will overwrite each other.) -- Unfortunately, the AfterPublish only runs on a successful publish; whereas `PostBuildEvent` could be set to run after a failed build. – BrainSlugs83 Jun 29 '21 at 21:23
  • None of my web site projects (vs web application projects) have csproj files. – paparush Mar 29 '23 at 13:00