Should NuGet.VisualStudio.Interop.dll be in the GAC to use it as a wizard? - visual-studio-2010

I am creating a project template. I would like to have it auto install unity and prism via NuGet.
I read here how to do that. I setup my vstemplate file like that page indicates:
<WizardExtension>
<Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>
<WizardData>
<packages>
<package id="CommonServiceLocator" version="1.0" />
<package id="Prism" version="4.1.0.0" />
<package id="Prism.UnityExtensions" version="4.1.0.0" />
<package id="Unity" version="2.1.505.0" />
</packages>
</WizardData>
It seems to be setup right, but it does not work. When I try to use my template I get this error message:
Could not add all required packages to the project. The following packages failed to install from 'C:\Users\MyUser\AppData\Roaming\Microsoft\VisualStudio\10.0\ProjectTemplatesCache\MyTemplate.zip'
I did some looking, and for a Wizard to work, it needs to be installed in the GAC. I ran this command:
gacutil.exe /l NuGet.VisualStudio.Interop
And it returned:
The Global Assembly Cache contains the following assemblies:
Number of items = 0
So it seems it is not in the GAC. The question is: How does this work for everyone else then? If it needs to be in the GAC, then why is it not there automatically?
If not, then why does it not work (I am fairly sure it needs to be in the GAC though).
Note: I did find that dll here:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft Corporation\NuGet Package Manager\1.6.21215.9133

I found that I had missed this important part of the docs:
The template needs to specify where to find the package nupkg files. Currently two package repositories are supported:
Packages embedded inside of a VSIX package.
Packages embedded inside of the project/item template itself.
So, there is no way to get packages from the actual NuGet Repository.

Answer for this Question:
Open Visual Studio > Tools > Extensions and Updates > choose Online link and then right side search bar type NuGet Package Manager. Then Download and Install. Solves your problem

Related

Manage Nuget Packages Outside Visual Studio

My organization wants to segregate all the development machines on a network without internet access.
I found this article that gives that gives some nuget host product, so that the packages are available offline.
My problem is that I can't find a way to manage the package update, because the machines that have and internet access won't have Visual studio installed.
I was looking if there is a tool that reads a folder where all nupkg files are stored and check if a newer version is available and downloads it, or otherwise reads a manually created packages.config file checks for newer version and download them on a folder.
Does anyone have an idea how to manage nuget packages in this way? I spent the last week trying to find a way but I had no look.
Does anyone have an idea how to manage nuget packages in this way?
According to the NuGet CLI reference:
The update command also updates assembly references in the project
file, provided those references already exist.
So when we use NuGet.exe update the package, we are not only need the packages.config but also need the solution/project, otherwise, you will get the error:
"Unable to locate project file for 'D:\NuGetServer\packages.config'
You can copy a simple project from the machine, which have Visual Studio installed, then use below command line to update the nuget package in the package.config file:
nuget update "YourProjectPath\packages.config"
But NuGet will update the packages into the packages folder under the solution folder by default, so we need change the packages folder to the folder where all nupkg files are stored before update packages.
Detail steps:
Download the nuget.exe from nuget.org, set it to your local machines.
Create a NuGet folder under the path %appdata%, add the NuGet.Config file and change the packages folder by repositoryPath, just set it "D:\NuGetServer":
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<config>
<add key="repositoryPath" value="D:\NuGetServer" />
</config>
</configuration>
Copy a solution from other machine, add the packages in to the package.config file:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
<package id="NUnit" version="3.7.0" targetFramework="net45" />
</packages>
Open a CMD file, switch to the path where NuGet is stored in step 1, then use the update command:
You will find packages in the packages.config are updated to the latest version.

how to fix ChakraCore NuGet package error?

When initializing a new React Native Windows WPF project, this error happens:
NuGet Package restore failed for project Native: Unable to find version '1.4.1-preview-00010-42060' of package 'Microsoft.ChakraCore'.
https://www.myget.org/F/chakracore-preview/api/v3/index.json: Package 'Microsoft.ChakraCore.1.4.1-preview-00010-42060' is not found on source 'https://www.myget.org/F/chakracore-preview/api/v3/index.json'.
https://api.nuget.org/v3/index.json: Package 'Microsoft.ChakraCore.1.4.1-preview-00010-42060' is not found on source 'https://api.nuget.org/v3/index.json'.
If I create a standalone project and add the same NuGet package reference, I get the same error -- even on Xamarin Studio Mac.
The problem is that the project was referencing the "preview" feed on myget.org, instead of the official release feed on nuget.org. In the NuGet.Config file(s) in your project, remove line that references the preview feed that looks like this:
<add key="ChakraCore" value="https://www.myget.org/F/chakracore-preview/api/v3/index.json" />
In the Visual Studio 2015 (or Xamarin/Visual Studio Mac) project, right-click on the project and select Manage NuGet References. From there, you can click on the Updates tab, select ChakraCore from the list, and click "Update". This should update the packages.config and other files for you. Note that if you had the project open while editing the config files you'll need to close and re-open the project to get the new settings to take hold. In some cases, the upgrade may leave behind the reference to the previous 1.4.1-preview package and you'll need to hand-edit the csproj file to get rid of it.
If you need to make this change without Visual/Xamarin Studio, you just have to edit a few text files. In the packages.config (in Visual Studio 2015), change the line referencing the 1.4.1-preview version to the latest release (1.5.2 as of this writing):
<package id="Microsoft.ChakraCore" version="1.4.1-preview-00010-42060" targetFramework="net46" developmentDependency="true" />
becomes
<package id="Microsoft.ChakraCore" version="1.5.2" targetFramework="net46" developmentDependency="true" />
In your project's csproj file:
<Import Project="$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" />
becomes
<Import Project="$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props')" />
and
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
becomes
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
Generally speaking, don't reference preview packages from myget.org in production projects or project templates others will use. They can be removed at any time, and security updates may not be published there with the same regularity as official channels.
Looks like the preview Microsoft.ChakraCore NuGet package was removed from the MyGet feed.
The main NuGet.org site only has stable releases for the Microsoft.ChakraCore NuGet package.
So you are left with editing any references to the package and using a published version. Microsoft.ChakraCore version 1.4.4 should work.
There is also an open issue about this on the React native GitHub site.

Nuget Restore Doesn't work at all

A Project with NuGet packages won't compile, the error is: "The project references NuGet package(s) that are missing on this computer, Enable NuGet Package Restore to download them."
Here's the Nuget Restore Option in Visual Studio:
If I look at the reference in the project, I see more than just the Nuget Packages missing!
If I attempt a restore at Solution layer...
If I attempt the Package Manager Console option of:
update-package -reinstall -projectname myProjectName
The output window successfully uninstalls and then reinstalls all the packages!
None of the references are good they are still all Yellow-Flagged as in the image above.
The Packages.Config File looks like this:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.4.0" targetFramework="net45" />
<package id="Selenium.Support" version="2.53.1" targetFramework="net45" />
<package id="Selenium.WebDriver" version="2.53.1" targetFramework="net45" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.23.0.1" targetFramework="net45" />
</packages>
When did this start failing?
Today I had to create a solution that included all the projects in a folder (with just one of them being the one shown in example above). I named it the AllSolutions.sln. When I added all of those projects, I got Nuget errors saying pacakges were missing. I attempted, with success, restoring all NUGET pkgs. using the solution level "Restore all Packages". The compile then worked for AllSolutions.sln.
I then opened a single one of the solutions from my C:drive (mapped to TFS properly). This is when the problem shown above surfaced.
Compile is working now, here was the solution:
I restarted Visual Studio, connected to TFS and clicked on the same solution as before. But this time, the project had new items in it as follows:
The .nuget folder was the original folder which apparently disappeared when I included this project in the AllSolutions.sln. (Note I did not manually delete this folder). The second is an internal project we have that just specifies what packages we use in the packages.config file.
I have no idea why reconnecting to TFS, opening the Solution file from the Team Explorer menu, (after a VS reboot) fixed this issue. But maybe this will help someone else.
And as proof, the original "Yellow Tagged" references shown above now look like this:
Root Cause:
I believe that including the same project in multiple projects has side effects related to Nuget restrore. The reason is that the .nuget folder is removed as shown in this post.
What was learned:
Migration of Nuget scripts was not necessary.
If your project is having this problem it can be related to a missing .nuget folder! Good luck in getting it restored.

Can NuGet install the source of a binary alongside so the reference can be debugged?

I am not very familiar with NuGet and I am wondering if NuGet offers a similar feature to Maven where I can choose to not only install the binary of a dependency but also its source code and documentation.
So, when debugging my solution, I can follow the debugger into code running within a dependency declared and managed with NuGet. This would also have the advantage that when the binary package is updated, NuGet would pull the matching source code.
NuGet supports symbol packages which allow you to debug into a NuGet package's source code in Visual Studio.
However this only works if the creator of the NuGet package published a symbol package.
Yes, it is supported. Here is the relevant documentation:
Creating and Publishing a Symbol Package
Here is an example of our NuSpec-File. It ist so generic, that it's literally the same for every package:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<title>$title$</title>
<tags>$tags$</tags>
<owners>$owners$</owners>
<authors>$authors$</authors>
<version>$version$</version>
<description>$description$</description>
<copyright>$copyright$</copyright>
<requireLicenseAcceptance>$requireLicenseAcceptance$</requireLicenseAcceptance>
<releaseNotes>$releaseNotes$</releaseNotes>
</metadata>
<files>
<file src="readme.txt" />
<file src="\bin\Release\*.pdb" target="lib\net45" />
<file src="**\*.cs" target="src" exclude="obj\**"/>
<file src="**\*.vb" target="src" exclude="obj\**"/>
</files>
</package>
We also use the Visual Studio Extension "NuGet Deploy", you can find it in the VS Gallery.
If you still cannot Step into your package source code, make sure you loaded the symbols. Check it during dubugging in the Pane "DEBUG->Windows->Modules"

How are packages.config paths resolved?

I have a project with a packages.config file. I do have a corresponding library. When I attempt to build my solution in Visual Studio, it does find the library, and everything works. But Xamarin Studio on my mac fails to find the same library.
For me, part of the problem is that I don't understand how the contents of the "packages" file corresponds to the path. It's clearly not a direct correspondence.
Here is the packages.config file. The relevant package is "splat".
EDIT: the answer was apparently that I needed to restart my computer. That said, it would still be interesting to know how it chooses the path.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="portable-net45+wp80+win+MonoAndroid10+MonoTouch10" />
<package id="Splat" version="1.2.1" targetFramework="portable-net45+win+MonoAndroid10+MonoTouch10" />
</packages>
And here is my packages directory in the finder:
WJ-macbook:packages william$ ls -RF
./Splat.1.2.1:
Splat.1.2.1.nupkg lib/
./Splat.1.2.1/lib:
MonoMac/ monoandroid/
Net45/ monotouch/
NetCore45/ wp8/
Portable-Net45+WinRT45+WP8/
./Splat.1.2.1/lib/MonoMac:
Splat.dll Splat.dll.mdb
./Splat.1.2.1/lib/Net45:
Splat.dll Splat.pdb
./Splat.1.2.1/lib/NetCore45:
Splat.dll Splat.pdb Splat.pri
./Splat.1.2.1/lib/Portable-Net45+WinRT45+WP8:
Splat.dll Splat.dll.mdb
./Splat.1.2.1/lib/monoandroid:
Splat.dll Splat.dll.mdb
./Splat.1.2.1/lib/monotouch:
Splat.dll Splat.dll.mdb
./Splat.1.2.1/lib/wp8:
Splat.dll Splat.pdb
On Windows the NuGet installation process will actually modify the relevant project file to include a hint path for the packages. Here is a line taken directly from one of my projects
<Reference Include="EditorUtils, Version=1.3.0.0, Culture=neutral, PublicKeyToken=3d1514c4742e0252, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\EditorUtils.1.3.0.0\lib\net40\EditorUtils.dll</HintPath>
</Reference>
The HintPath here is the method by which MsBuild discovers the EditorUtils reference. This was added by NuGet during installation.
I do not know what the equivalent mechanism is on xamarin unfortunately although I imagine it's quite similar

Resources