Post Publish Events
Asked Answered
B

1

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#.

Brezin answered 1/9, 2009 at 4:53 Comment(0)
M
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.

Melaniemelanin answered 1/9, 2009 at 5:0 Comment(8)
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!Brezin
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.Barth
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.Melaniemelanin
@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.Professoriate
@Ian Grainger - It's been ~2 years since my answer. VS might have changed since then... :-)Melaniemelanin
@Sam.Rueby I have no idea. I haven't touched Azure (or VS for that matter) in about a year and a half. :-(Melaniemelanin
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.Unblinking
None of my web site projects (vs web application projects) have csproj files.Cuneo

© 2022 - 2024 — McMap. All rights reserved.