4

is there any way of setting and/or changing the post build event/action for all projects in an entire solution? I have some solutions with up to 50 projects in it which all need the same post build action except for 2 projects. When I have a new solution or I have to change the post build action for all projects of an existing solution, I have to run through all project settings, go to the compile tab page and edit the post build action.

Any other solution to be able to set a post build action for an entire solution would be appreciated as well. Maybe MS Build but I have no experience there...

Working with Visual Studio 2012 and VB.Net projects.

wdumon
  • 105
  • 1
  • 8

3 Answers3

1

You could create an simple application that can receive multiple .csproj files and and a simple multiline textbox where you can paste your postbuild actions.

So in 1 project edit the post build. Open the projectfile in notepad look for the <PostBuildEvent>...</PostBuildEvent> and paste this inside your multiline textbox and loop over all your projectfiles and add this xml element to them.

enter image description here

Jordy van Eijk
  • 2,718
  • 2
  • 19
  • 37
  • we thought about this as well but we're looking for something that's inherent to visual studio so we don't need another extra application to do things like this. – wdumon Mar 15 '13 at 08:17
1

I do this with Visual Studio macros.

In the macro editor (Alt + F11) there is the EvironmentEvents file.
Here I use the BuildEvents_OnBuildProjConfigDone event.
I use this all the time to copy assemlies to my working folder.

Example:

Private targetPath As String = "C:\..."  

Private Sub BuildEvents_OnBuildProjConfigDone(ByVal ProjectName As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String, ByVal Success As Boolean) Handles BuildEvents.OnBuildProjConfigDone
    On Error GoTo ext
    If Not Success Then Exit Sub

    'Absolute path to assembly
    Dim tar = targetPath
    Dim project As Project = DTE.Solution.Projects.Item(ProjectName)
    Dim projectFolder As String = Path.GetDirectoryName(project.FileName)
    Dim config As EnvDTE.Configuration = project.ConfigurationManager.ActiveConfiguration
    Dim outputPath As String = CStr(config.Properties.Item("OutputPath").Value)
    Dim assemblyName As String = CStr(project.Properties.Item("AssemblyName").Value)
    Dim assemblyFileName As String = CStr(project.Properties.Item("OutputFileName").Value)
    Dim src As String = Path.Combine(Path.Combine(projectFolder, outputPath), assemblyFileName)

    'Copy files to working folder
    On Error GoTo err
    Dim dst As String

    dst = Path.Combine(tar, assemblyFileName)
    DTE.ToolWindows.OutputWindow.ActivePane.OutputString(outTag + assemblyName + " -> " + dst + vbCrLf)
    File.Copy(src, dst, True)

    src = src.Substring(0, src.Length - 3) + "pdb"
    dst = dst.Substring(0, dst.Length - 3) + "pdb"
    DTE.ToolWindows.OutputWindow.ActivePane.OutputString(outTag + assemblyName + " -> " + dst + vbCrLf)
    File.Copy(src, dst, True)

    Exit Sub

err:
    DTE.ToolWindows.OutputWindow.ActivePane.OutputString(outTag + Err.Description + vbCrLf)
ext:
End Sub
joe
  • 8,344
  • 9
  • 54
  • 80
  • apparently the macro editor has been removed from Visual Studio 2012. Some suggest using add-ins to get the same behavior, I'll look into that with this suggestion. – wdumon Mar 15 '13 at 10:18
  • This means that i have to write my own VS add-in in the future to do things like above? – joe Mar 15 '13 at 19:17
  • I think so yes. I've haven't been digging deeper on this matter for now, but if you search for "macro editor in VS2012" all you get is examples to use the add-ins... – wdumon Mar 18 '13 at 08:41
0

Are you aware that you can select multiple projects in Solution Explorer (using Ctrl-pick or Shift-pick), then change all projects at once?

Owen Wengerd
  • 1,628
  • 1
  • 11
  • 11
  • You can select them but you don't get access to the post build events, which is on the 'Compile' tab page of the properties window. All you get when selecting multiple projects and opening the properties pane is 'project file' and 'project folder'? – wdumon Mar 15 '13 at 08:28
  • Sorry, my answer only applies to C++ projects. – Owen Wengerd Mar 15 '13 at 15:56