14

Closed

F# Project VS 2012: Update package removes HintPath

description

In F# projects in Visual Studio 11 beta and 2012 RC, updating to a newer version of a package strips the HintPath out of the *.fsproj file, which breaks my build server. Every time I update with NuGet, I have to manually fix my project file. This does not happen with C# projects in VS 11/2012, or with F# projects in VS 2010.

Before:
<Reference Include="Newtonsoft.Json">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\Newtonsoft.Json.4.5.3\lib\net40\Newtonsoft.Json.dll</HintPath>
  <Private>True</Private>
</Reference>
After:
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
  <Private>True</Private>
</Reference>
Then I have to manually fix it to:
<Reference Include="Newtonsoft.Json">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\Newtonsoft.Json.4.5.4\lib\net40\Newtonsoft.Json.dll</HintPath>
  <Private>True</Private>
</Reference>

file attachments

Closed Apr 5, 2013 at 3:24 AM by deepakaravindr

comments

happyrabo wrote Jun 2, 2012 at 4:13 AM

This issue is still present in VS 2012 RC.

happyrabo wrote Sep 12, 2012 at 11:12 PM

This issue is still present in VS 2012 RTM, with NuGet 2.0.30625.9003.

It is REALLY FRUSTRATING to manually edit every single one of my F# project files every time NuGet updates a package.

dotnetjunky wrote Oct 9, 2012 at 7:33 PM

It looks like NuGet is busted when installing packages into F# project in VS 2012.

coza99 wrote Oct 10, 2012 at 11:56 AM

Additionally, I have noticed the newest version of nuget 2.1.xxxx also skips editing the packages.config to the correct version

deepakaravindr wrote Oct 26, 2012 at 12:38 AM

I am unable to repro the bug.
A fix on F# was checked in on 10/23 (c7c769888ffd2448ecbc57843bd5c36b8f7933b9). I presumed it may have fixed this issue. But, when I tried with a vsix created on 2012-10-19, the issue still could not be reproed

In any case, the bug certainly does not repro after the aforementioned fix related to packages.config on an F# application

deepakverma wrote Nov 9, 2012 at 8:08 PM

couldn't repro this with the upcoming 2.2 version, hence closing this.

** Closed by deepakverma 11/09/2012 12:08PM

dna wrote Nov 30, 2012 at 11:05 AM

Its very easy to reproduce:

Open VS2012 (with Nuget 2.2 installed), create a new F# project.

Add your first NuGet Package -> works. Library is referenced and packages.conf is filled.

Add another NuGet Package -> does not work correctly. Reference to project is added, but package is not added to packages.conf

happyrabo wrote Dec 13, 2012 at 3:48 PM

This issue is still present in NuGet 2.2 and Visual Studio 2012. When upgrading Newtonsoft.Json from 4.5.7 to 4.5.11, this is what happens to every single one of my *.fsproj files.

Before:
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll</HintPath>
  <Private>True</Private>
</Reference>
After:
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
  <Private>True</Private>
</Reference>

happyrabo wrote Dec 13, 2012 at 4:18 PM

The exact same operation in a C# project in VS 2012...

Before:
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
After:
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>

happyrabo wrote Dec 13, 2012 at 5:52 PM

I'm attaching a simple solution zip that reproduces the problem.
  1. Edit Issue2149Repro.fsproj and note that the Newtonsoft.Json reference looks like this:

    <Reference Include="Newtonsoft.Json">
    <HintPath>..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll</HintPath>
    <Private>True</Private>
    </Reference>
  2. Open the solution and build it. The issue does not occur unless the project has been compiled.
  3. Use the NuGet GUI in Visual Studio 2012 to update Json.NET to the latest version, then save the project.
  4. Edit the project file again, and notice that the Newtonsoft.Json reference now looks like this:

    <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
    <Private>True</Private>
    </Reference>

henke wrote Dec 16, 2012 at 10:05 PM

Do we get this fixed for Christmas?

deepakverma wrote Jan 23, 2013 at 8:04 PM

I was able to repro the issue on VS 2012 RTM + nuget 2.2 with the attached project.

deepakaravindr wrote Apr 3, 2013 at 6:47 PM

Tried a sample application in which references were added (OR removed from) programmatically to an FSharpLibrary project. Hintpath is not added after Step-3 below. Steps 2 and 3 below are performed by NuGet while Updating a package. Hence, the bug
  1. Add Reference programmatically to an FSharpLibrary Project. Build it (MANDATORY). Hint path is added fine
  2. Remove Reference. Don't do anything before Step-3 like save or remove
  3. Add Reference programmatically to the project. Hint path is not added this time
Will follow up with FSharp team about this behavior. Will update with workaround if I find one

deepakaravindr wrote Apr 3, 2013 at 7:43 PM

In addition, Adding Reference programmatically to an FSharp Project does not add the HintPath, as one would expect, only when the dll is already present in the bin\Debug directory

Hence, the building project is a mandatory part in the repro steps. Since, that is when the binaries are copied over to the bin\Debug. And, Updating the package after that point does not add the reference like in C#

happyrabo wrote Apr 4, 2013 at 7:09 PM

The only workaround I've found is to remember to do a Build...Clean before updating any references using NuGet. That way the assembly is not present in the output folder, and the hintpath is set correctly.

deepakaravindr wrote Apr 5, 2013 at 3:23 AM

That is correct. Clean before update is the best workaround when the issue is known

F# knows about this behavior and they will release the fix

There is a possible code workaround. But, if we added it now, it stays on forever. This way, we lose out on the goodness the F# fix can bring. For these reasons, we suggest the following workaround. Closing this issue
  1. If the issue is known, clean the solution before performing Update-Package
  2. If already broken, clean the solution, uninstall the package, install it back
  3. Jeff suggested a simpler “Update-Package –reinstall” workaround. Unfortunately, due to another bug in F# project system, only pertaining to “UpdatePackage in PMC”, we cannot suggest that. There is no way to perform -reinstall from dialog window. If I find more information on when the other fix will be available, I will update this issue