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.
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
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.
您是否知道可以在解决方案资源管理器中选择多个项目(使用Ctrl-pick或Shift-pick),然后一次更改所有项目?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.