Post Publish Events
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.
Russell
I am an Architect and Senior developer based in Adelaide. I love learning, mentoring and contributing to the development community. You can find me on Twitter @RussLescai.
Updated on July 09, 2022Comments
-
Russell almost 2 years
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 over 14 yearsThanks, 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!
-
AMissico over 14 yearsI 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.
-
Franci Penov over 14 yearsIt'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.
-
Auguste Van Nieuwenhuyzen almost 13 years@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.
-
Franci Penov almost 13 years@Ian Grainger - It's been ~2 years since my answer. VS might have changed since then... :-)
-
Franci Penov about 12 years@Sam.Rueby I have no idea. I haven't touched Azure (or VS for that matter) in about a year and a half. :-(
-
BrainSlugs83 almost 3 yearsIts 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 anAfterTargets="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; whereasPostBuildEvent
could be set to run after a failed build.