How do multiple projects have the same post-build event?

2

I have a Visual Studio solution with 277 projects. And I would like everyone to have the same post-compilation event. Basically, they would run an executable that is in the application folder. Anyone have any suggestions?

    
asked by anonymous 06.04.2015 / 20:14

3 answers

2

I found a solution in a answer in the SO . I do not know if she catches you but it's a way. On the same page are other solutions, including plugin .

    
06.04.2015 / 20:21
2

Create a program to open each project and then add the post-build section.

It would look like this:

foreach (var caminhoDoProjeto in Directory.GetFiles(
    "caminho/da/solucao",
    "*.csproj",
    SearchOption.AllDirectories))
{
    var xdoc = XDocument.Load(new StringReader(File.ReadAllText(caminhoDoProjeto)));
    XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003";
    var event = xdoc.Descendants(msbuild + "PostBuildEvent").SingleOrDefault();
    if (event == null)
    {
        var group = new XElement(msbuild + "PropertyGroup");
        event = new XElement(msbuild + "PostBuildEvent");
        group.Add(event);
        xdoc.Root.Add(group);
    }
    event.Value = postEventText;
    xdoc.Save();
}

P.S. Backup and debugging it there to make sure it will not give you any problems ... no warranties, I DID NOT TEST.

    
06.04.2015 / 20:38
2

Visual studio allows you to create postbuild events using this feature you can create bat files to proceed with what interests you, the bad thing is that even if the postbuild script is the same you will have of doing it (copy / past) in all the projects of its solution, follows an example for you to customize.

    <PostBuildEvent>
      MOVE /Y "$(TargetDir)something.file1" "$(ProjectDir)something.file1" start XCOPY /Y /R "$(SolutionDir)SomeConsoleApp\bin\$(ConfigurationName)\*"     "$(ProjectDir)App_Data\Consoles\SomeConsoleApp\"
    </PostBuildEvent>
    
07.04.2015 / 16:32