control nuget package restore w/o changing project settings

Mar 6, 2012 at 5:20 PM

After installing mvc4 beta and the nuget package manager extension 1.6.30117.9648 that came with it i'm now finding that all my solutions containing projects with nuget packages are automatically pulling all the referenced packages and adding them to source control pending changes when I open the solution.

I read the 1.6 release notes on the new first class support for the workflow in which NuGet packages are not added to source control, but instead are restored at build time if missing.  

My challenge is I do not want the option nuget adding packages in source control and i also would like to avoid having a $(SolutionDir)\.nuget folder with NuGet.exe and NuGet.targets in my source control and the required edits to each of the projects in the solution.

Is there a way that I can turn off both nuget package manager source control integration behavior and also turn off having it require the alternative $(SolutionDir)\.nuget settings to restore packages at build time?    The reason I ask is because i'd like to just keep using my simple solution that has been working fine on dev/test and automated build machines which involves setting <project using nuget packages> | properties | build events | prebuild build event = [ %windir%\nuget.exe install "$(ProjectDir)packages.config" -o "$(SolutionDir)packages" ]

My preference for this model is because it doesn't requirement me changing any solution contained project settings or maintaining any $(SolutionDir\,.nuget folder NuGet.exe and NuGet.targets in source control.

Mar 6, 2012 at 6:38 PM

I assume you're using TFS. Can you just ignore the packages in pending changes that you don't want to version, and keep doing what you've been doing?

Mar 6, 2012 at 9:00 PM

yes i'm using tfs.   I used undo to remove the \packages folder pending changes the first time it happened but it repeats every time I reopen the solution.   I want to have it never happen and leaving them as pending is dangerous cause I don't want any of it inadvertently getting checked in.  Likewise when having to undo those pending changes that get created every time I now open the solution/project it risks that I inadvertently undo one of my actual source code pending changes I need to eventually submit.

Mar 6, 2012 at 11:12 PM

Is there no way to permanently ignore files in TFS? (I know very little about TFS; I would have to defer to other folks in the team that know more).

Developer
Mar 7, 2012 at 3:53 PM

You can add a nuget.config under the .nuget directory of your solution (create it if you don't have one) with the following contents

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <solution>
        <disableSourceControlIntegration>true</disableSourceControlIntegration>
    </solution>
</configuration>
Mar 7, 2012 at 3:56 PM

Sweet, thanks @pranavkm, I did not know that. (Still, please tell me you can ignore files in TFS!?)

Developer
Mar 7, 2012 at 4:07 PM

Once you add that, we will not check the packages directory in to source control. I believe Package restore auto adds this file for you.

Mar 9, 2012 at 4:21 PM
Edited Mar 11, 2012 at 2:54 PM

I created a folder $(SolutionDir).nuget and in it added a nuget.config file containing the following content.   After that when I open the solution I still find that nuget packages are all being automatically added to my source control setup as pending changes.   I also tried with the $(SolutionDir).nuget folder and the nuget.config file it contained added to the solution view and still the $(SolutionDir)packages pending changes get created when i open the solution.  

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <solution>
        <disableSourceControlIntegration>true</disableSourceControlIntegration>
    </solution>
</configuration>

Any thoughts on what i'm overlooking that is necessary to get this proposed workaround working?

Mar 11, 2012 at 2:53 PM

I have come back and edited my previous reply because the initial results I posted were not accurate.   So at this point i'm still stuck w/o a way to have nuget package manager extension exclude trying to ensure tfs source control bits are in place while also not using the new 1.6 release feature that requires modifying project file settings in every solution contained project just to disable this from happening for the few that use nuget packages.   As noted above what i'm looking to use instead is just a simple prebuild event in the projects that have nuget package dependencies consisting of "%windir%\nuget.exe install "$(ProjectDir)packages.config" -o "$(SolutionDir)packages".

Would appreciate any additional thoughts on how I get this working.

Mar 14, 2012 at 4:03 PM

After some more trial and error I've found that if I create a $(SolutionDir).nuget folder containing a nuget.config file containing only the following content

<?xml version="1.0" encoding="utf-8"?>

then when I open the solution it no longer tries to add $(SolutionDir)/packages content to tfs source control and i also didn't need to make any solution project setting changes which is what I was looking for.

Does this result make sense? 

Going forward it would be desirable to support not even having to add this essentially empty $(SolutionDir).nuget/nuget.config file in order to use the option I discuss above.   That is one where I don't have to make solution wide project setting changes that add an import for $(SolutionDir).nuget\NuGet.Targets and i don't have to source control checkin and maintain a NuGet.exe on a per solution basis and instead use the simple approach that has been working well for us involving <project using nuget packages> | properties | build events | prebuild build event = [ %windir%\nuget.exe install "$(ProjectDir)packages.config" -o "$(SolutionDir)packages" ].  

Developer
Mar 15, 2012 at 10:40 AM

Wouldn't it be easier to replace the $(NuGetExePath)  variable in the targets file?

Mar 15, 2012 at 2:56 PM

Didn't think of that.   So if I placed NuGet.exe and NuGet.config in my %windir% and updated the $(SolutionDir).nuget\NuGet.targets file path setting for $(NuGetExePath) then it would seem I could achieve not having duplicate copies of that binary maintained all over my source control.   

Should be able to do a similar thing with $(SolutionDir).nuget\NuGet.targets and instead, e.g. drop a copy of it in "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0" and "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0" and then just edit each of my solution projects that have nuget packages to contain an <Import Project="C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v1#.0\nuget.targets" /> entry instead?

This way the default behavior for all projects would be to just add that import statement and expect dev and test workstations along with build machines to all have the binaries, config and target files in the non-source control centrally maintained locations.