2

I have a project file that should build another solution. I tried using the MSBuild task for this, like this:

<MSBuild Projects="MySolution.sln" Properties="Configuration=$(Configuration)"/>

I tried a lot of variants, like supplying hardcoded configuration, target Rebuild and so on. Building reports an error when I pass a wrong solution name, non-existing configuration or target and so on, so it definitely loads the solution and the project files. It exits relatively fast though and produces no output. According to documentation and examples, this should work though. I also tried passing an ItemGroup for the project, including project-specific properties as suggested by examples or in MSBuild - How to build a .NET solution file (in an XML task script) from pre-written command line commands , but that does not work either. It runs without error but no output.

When passing a list of project files instead (or a single project file), it builds correctly, but the problem is that dependencies between the projects are not properly resolved. At the end, I have to supply all project files in the solution and add them to the list, which is what I want to avoid.

So, why does solution building not work, even though it should? What is wrong here?

Community
  • 1
  • 1
OregonGhost
  • 23,359
  • 7
  • 71
  • 108

1 Answers1

1

Is this a .net project? If so you probably need to pass in a platform as well as a configuration.

<MSBuild
  Projects="MySolution.sln"
  Targets="build"
  Properties="Configuration=$(Configuration);Platform=$(Platform)" />

If the project just contains web sites and libraries then the platform should be Any CPU if your solution just contains executables then x86 or x64 or if it's a mixture of different types of platform then you can use mixed platforms

To check what are available open the solution in Visual Studio, right click on the solution in solution explorer and select "Configuration Manager" you'll then have a drop down for "Active Solution Platforms" Active Solution Platforms

James Reed
  • 13,873
  • 51
  • 60
  • OK, that was the problem. Passing "Any CPU" will work correctly. Passing $(Platform), however, does not work, even though I'm in Any CPU build. The passed value is "AnyCPU" (without a space). Any idea why's that? – OregonGhost Sep 21 '15 at 09:37
  • Yes, and I discovered yet another bug: For some reason, when building like this, MSBuild does not maintain project dependencies. An official statement is that it does this when either the Configuration or the Platform is not found in the solution, but in this case, both are. And if specifying the "wrong" platform, it does not build anything. I'm trying to this with Exec instead of MSBuild, but that leads to the next problem (finding msbuild.exe)... – OregonGhost Sep 21 '15 at 11:33
  • We're, for now, back to building the single projects in the right order, rather than depending on the solution. This works quite well, with the only disadvantage being that I have to maintain the list. But then, we only need a few projects from the solution... – OregonGhost Sep 23 '15 at 09:11
  • The bug from "Any CPU" is actually due to White Space, and still occurs is VS2015. Need to call it with quotes surrounding the value. – kayleeFrye_onDeck Jul 20 '17 at 02:24