Bug 25353 - MSBuild configurations set incorrectly
Summary: MSBuild configurations set incorrectly
Status: NEW
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Project Model ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: master
Assignee: Lluis Sanchez
URL:
Depends on:
Blocks:
 
Reported: 2014-12-12 15:58 UTC by Mikayla Hutchinson [MSFT]
Modified: 2014-12-12 15:58 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 25353 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Mikayla Hutchinson [MSFT] 2014-12-12 15:58:48 UTC
Before building a project, the MSBuild 4.0+ project builder uses project.SetProperty to set the solution-mapped Configuration and Platform values on each Project in the ProjectCollection. It then creates a ProjectInstance and builds it.

This is incorrect. SetProperty inserts a property on the first PropertyGroup in the project that already contains a value for that property, which means anything that checks the value before that property (e.g. an imported pros file) will not see the value.

This can be demonstrated by adding the following project to a solution and building it. This fails in XS/MD and succeeds in VS.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Fail>false</Fail>
    <Fail Condition="'$(Configuration)' == ''">true</Fail>
  </PropertyGroup>
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Target Name="BeforeBuild">
  	<Error Condition="$(Fail)=='true'" Text="Configuration not set" />
  </Target>
</Project>

Unfortunately the fix is not as simple as using SetGlobalProperty.

I think we may need to use Microsoft.Build.Execution.BuildManager. We'd build each project, only setting the Configuration/Platform for each individual project as we built it. If we build each project's dependencies before it, then the BuildManager would re-use the existing ProjectInstances with the property values that we already set on it.