Bug 39882 - Moving Xamarin.Forms projects breaks all references
Summary: Moving Xamarin.Forms projects breaks all references
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.1.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-03-24 07:26 UTC by Willem Mali
Modified: 2016-03-24 13:40 UTC (History)
2 users (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 ANSWERED

Description Willem Mali 2016-03-24 07:26:21 UTC
Hi, I was moving around some of my projects and after making the necessary changes in my solution to have them show up again, literally all references where mysteriously broken!

I tried manually reinstalling NuGet packages and a bunch of combinations of resets/reinstalls of VS / NuGet / NuGet Packages but that didn't do anything. In the end the culprit turned out to be this:

  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\..\packages\Xamarin.Forms.2.1.0.6526\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.2.1.0.6526\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets'))" />
    <Error Condition="!Exists('..\..\..\packages\Xamarin.Forms.2.1.0.6529\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Xamarin.Forms.2.1.0.6529\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets'))" />
  </Target>

This happened to all my .csproj files: an error condition was added but the old one wasn't removed, so it always occured, and this somehow made it so that none of my references would load. Removing the old Error fixed the problem.
Comment 1 Matt Ward 2016-03-24 09:29:12 UTC
That error condition is added by NuGet in Visual Studio. If you move the projects around then I guess NuGet did not properly remove that information. Although I would have expected that if you had used 'Update-Package -reinstall' from the Package Manager Console NuGet should have fixed this but maybe it uses the full path to the .targets file and fails to match it due to the different location.

This is a NuGet problem and not something that can be fixed by the Forms NuGet package. If you can repro this then it is probably worth filing a bug against NuGet on https://github.com/nuget/home/issues
Comment 2 Willem Mali 2016-03-24 13:29:15 UTC
I have tried Update-Package -reinstall but this changed nothing (literally; I checked the diffs). The error condition is added by the Xamarin Forms NuGet package and not by NuGet itself; no other packages I use creates this kind of error conditions. Why do you say this is a NuGet bug, what indicates it's not specific to the Xamarin Forms package?
Comment 3 Matt Ward 2016-03-24 13:40:00 UTC
The error condition is not added by Xamarin.Forms NuGet package itself. It is added by the NuGet Package Manager in Visual Studio when it installs Xamarin.Forms since the Xamarin.Forms NuGet package uses a custom MSBuild targets file. It adds an Import for the MSBuild targets file and then adds the EnsureNuGetPackageBuildImports with error conditions. This is not something the Xamarin.Forms NuGet package can fix since it needs the MSBuild targets to generate code from the Forms .xaml files in your project.

If you install another NuGet package that uses a custom MSBuild .targets file, such as Microsoft.Bcl.Build, into a new C# project you will see the same error condition added inside the EnsureNuGetPackageBuildImports target. These are added by the NuGet package manager in Visual Studio.

If you use Xamarin Studio and install the Xamarin.Forms NuGet package then this EnsureNuGetPackageBuildImports target is not added, nor or any error conditions added, since the NuGet addin in Xamarin Studio does not support the EnsureNuGetPackageBuildImports target.