Bug 19054 - NuGet package MSBuild property files (.props) should be added to the start of the project file
Summary: NuGet package MSBuild property files (.props) should be added to the start of...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: NuGet ()
Version: 5.0
Hardware: All All
: High major
Target Milestone: master
Assignee: Matt Ward
URL:
: 19053 ()
Depends on:
Blocks:
 
Reported: 2014-04-15 10:03 UTC by Matt Ward
Modified: 2016-04-01 14:50 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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Matt Ward 2014-04-15 10:03:47 UTC
Currently any custom MSBuild property files (.props) that are contained in a NuGet package are added at the bottom of the MSBuild project file (.csproj). This is OK for custom MSBuild targets files (.targets) but the property files should be added at the top of the MSBuild project file.

Test NuGet package that contains both .targets and .props is Test.Import.Foo

Adding this NuGet package using Visual Studio updates the .csproj file as follows:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="packages\Test.Import.Foo.0.6\build\Test.Import.Foo.props" Condition="Exists('packages\Test.Import.Foo.0.6\build\Test.Import.Foo.props')" />
  <PropertyGroup>

So the .props <Import> is the first thing inside the <Project> element.

There are very few NuGet packages available on nuget.org that use .props files.

This also requires more changes on the MSBuild - Project system. Currently only the import file name is passed as a string to the project system without any indication where the import should be stored in the project file. The changes would need to be made in the DotNetProject and MSBuildProjectHandler classes.
Comment 1 Matt Ward 2014-04-15 10:17:52 UTC
*** Bug 19053 has been marked as a duplicate of this bug. ***
Comment 2 Prashant manu 2014-05-02 10:02:35 UTC
We have tried to replicate this issue at our end. We added 'Test.Import.Foo' NuGet package in VS android project. targets and .props files present for this package. But in .csproj file we are not seeing

"<Project ToolsVersion="4.0" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="packages\Test.Import.Foo.0.6\build\Test.Import.Foo.props"
Condition="Exists('packages\Test.Import.Foo.0.6\build\Test.Import.Foo.props')"
/>
  <PropertyGroup>
"
and hence not seeing .props <Import> as the first thing inside the <Project>

Screencast: http://screencast.com/t/RGgZhcZ2HNv4

Please provide us some suggestions/directions so that we can compare the behaviors in VS and XS.
Comment 3 Matt Ward 2014-05-02 10:33:39 UTC
Created attachment 6711 [details]
Example project with .props import

Try a C# console application. Example project is attached after installing the NuGet package.
Comment 4 Matt Ward 2014-05-02 10:39:03 UTC
It also adds the .props import when I install it into an Android project in Visual Studio 2010.
Comment 5 Mikayla Hutchinson [MSFT] 2016-03-01 19:59:45 UTC
This breaks any NuGet with props files. The entire *point* of the props (versus targets) is to be imported at the beginning of the file.
Comment 6 xamarin-release-manager 2016-03-22 09:38:55 UTC
Fixed in version 6.1.0.355 (master)

Author: Matt Ward
Commit: 569d5e819fa015b45876f61c1c574f8a4b1070cf (mono/monodevelop)
Comment 7 xamarin-release-manager 2016-03-22 09:45:24 UTC
Fixed in version 6.0.0.4856 (cycle7)

Author: Matt Ward
Commit: 45ff88b93c2219fc66b27b45a7871321670f019a (mono/monodevelop)
Comment 8 xamarin-release-manager 2016-04-01 14:50:22 UTC
Fixed in version 6.0.0.4918 (cycle7-android-n)

Author: Matt Ward
Commit: 45ff88b93c2219fc66b27b45a7871321670f019a (mono/monodevelop)