How to make several projects have the same post-compilation event?

Asked

Viewed 89 times

2

I have a solution in Visual Studio 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. Does anyone have any suggestions?

3 answers

2


I found a solution in a response in the OS. I don’t know if it serves you but it is a way. On the same page there are other solutions, including plugin.

2

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

It would look something 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. Back up and will debug it there to make sure it will not give no problem... no guarantees, I DID NOT TEST.

2

The visual studio allows you to create post-build events (postbuild Events) with the use of this feature you can create bat files to proceed with whatever is of interest to you, the bad thing is that even if the postbuild script is the same you will have to do it (copy/Past) in all projects of your 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>
  • I had already thought about it. But the problem is the dependencies, where for example, when compiling the project x, it calls y, z, k....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.