locked
how to automatically build Solution1 every time Solution2 is built RRS feed

  • Question

  • How would I write visual studio shell code that would automatically build a solution everytime another solution is built?

    I have the same class library project in two different visual studio solutions. Since both solutions are packages, when I start a VS2010 experimental instance to test a package, the shell loads the shared class library from the first package. But if a method was added to the shared class library thru the 2nd package solution I get an error in visual studio experimental instance saying the method is not found. I have to make sure to build both solutions.

    Does visual studio already have a feature that builds multiple solutions whenever one of the solutions is built?

    thanks,

    Wednesday, March 28, 2012 12:45 AM

Answers

  • No, you can't load two solutions at the same time, so no facility exists for building a different, non-loaded solution. You can have multiple projects under a single solution, so you could simply make a single solution that builds the shared project and both packages.

    Ryan

    • Marked as answer by Steve Richter Wednesday, March 28, 2012 1:42 PM
    Wednesday, March 28, 2012 1:03 AM
  • If you can develop a package, what about a command line executed each time you start the build process? but you won't have any support for errors in the IDE I guess.

    • Edited by baccali Wednesday, March 28, 2012 3:20 AM
    • Marked as answer by Steve Richter Wednesday, March 28, 2012 1:42 PM
    Wednesday, March 28, 2012 3:11 AM
  • Hi again Steve,

    I did some search and apparently I found a solution that let you bypass the command line and launch msbuild directly with code. Take a look at this post. I didn't try it but It should solve your problem and it seems you can even log the exceptions generated on the output window/Error list. (Note that without coding, you can also simply add the command line in the "post-build task" if it is ok with what you need)

    Cheers

    • Edited by baccali Wednesday, March 28, 2012 11:46 PM
    • Marked as answer by Steve Richter Thursday, March 29, 2012 12:41 AM
    Wednesday, March 28, 2012 11:24 PM

All replies

  • No, you can't load two solutions at the same time, so no facility exists for building a different, non-loaded solution. You can have multiple projects under a single solution, so you could simply make a single solution that builds the shared project and both packages.

    Ryan

    • Marked as answer by Steve Richter Wednesday, March 28, 2012 1:42 PM
    Wednesday, March 28, 2012 1:03 AM
  • If you can develop a package, what about a command line executed each time you start the build process? but you won't have any support for errors in the IDE I guess.

    • Edited by baccali Wednesday, March 28, 2012 3:20 AM
    • Marked as answer by Steve Richter Wednesday, March 28, 2012 1:42 PM
    Wednesday, March 28, 2012 3:11 AM
  • If you can develop a package, what about a command line executed each time you start the build process? but you won't have any support for errors in the IDE I guess.

    Something like that. Thanks. I would like to automate it.  Hook the OnBuildDone event which in turn starts another instance of visual studio that then automatically starts a build of the other solutions.

    Wednesday, March 28, 2012 1:42 PM
  • Hi again Steve,

    I did some search and apparently I found a solution that let you bypass the command line and launch msbuild directly with code. Take a look at this post. I didn't try it but It should solve your problem and it seems you can even log the exceptions generated on the output window/Error list. (Note that without coding, you can also simply add the command line in the "post-build task" if it is ok with what you need)

    Cheers

    • Edited by baccali Wednesday, March 28, 2012 11:46 PM
    • Marked as answer by Steve Richter Thursday, March 29, 2012 12:41 AM
    Wednesday, March 28, 2012 11:24 PM
  • I did some search and apparently I found a solution that let you bypass the command line and launch msbuild directly with code. Take a look at this post. I didn't try it but It should solve your problem and it seems you can even log the exceptions generated on the output window/Error list. (Note that without coding, you can also simply add the command line in the "post-build task" if it is ok with what you need)

    very nice. Thanks.

        static void BuildSolution(string SolutionPath )
        {
          var pc = new ProjectCollection();
          var GlobalProperty = new Dictionary<string, string>();
          GlobalProperty.Add("Configuration", "Debug");
          GlobalProperty.Add("Platform", "Any CPU");
    
          var buildRqs = new BuildRequestData(
            SolutionPath, GlobalProperty, null, new string[] { "Build" }, null);
          var buildResult = BuildManager.DefaultBuildManager.Build(new BuildParameters(pc), buildRqs);
          Trace.WriteLine(buildResult.OverallResult.ToString());
          if (buildResult.OverallResult == BuildResultCode.Failure)
          {
            if ( buildResult.Exception != null )
              Trace.WriteLine(buildResult.Exception.ToString());
          }
          foreach (var tgt in buildResult.ResultsByTarget)
          {
            Trace.WriteLine("Key:" + tgt.Key + " Result:" + tgt.Value.ResultCode.ToString());
          }
        }
    

    Thursday, March 29, 2012 12:41 AM