Matt Ward

NuGet Support in Visual Studio for Mac 8.6

Changes

  • NuGet 5.6 support
  • Fixed escape key not closing Manage NuGet Packages dialog

More information on all the new features and changes in Visual Studio for Mac 8.6 can be found in the release notes.

NuGet 5.6 support

NuGet 5.6.0.6591 is now included with Visual Studio for Mac 8.6.

Bug Fixes

Fixed escape key not closing Manage NuGet Packages dialog

When the search text box had focus pressing the escape key would not close the Manage NuGet Packages dialog as it did in previous versions. A change to fix accessibility of the search text box broke the original behaviour of the dialog.

Manage Global NuGet Folders for Visual Studio for Mac

NuGet supports configuring the location of the following global folders:

  • Global NuGet packages cache
    • ~/.nuget/packages
  • HTTP cache
    • ~/.local/share/NuGet/v3-cache
  • NuGet plugins ache
    • ~/.local/share/NuGet/plugins-cache

The above folder locations can be found by running the following command from Terminal.

nuget locals all -list

Here we will take a look at how these can be configured for use by Visual Studio for Mac 8.5 when running on macOS Catalina.

Configuring Global Packages Folder Only

If only the global packages folder needs to be configured then the simplest way is to define the globalPackagesFolder folder in the ~/.config/NuGet/NuGet.Config file.

1
2
3
4
5
6
7
8
<configuration>
  <config>
    <add key="globalPackagesFolder" value="/Volumes/YourDrive/NuGet/.nuget/packages" />
  </config>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

Visual Studio for Mac will need to be restarted before it picks up any changes to the NuGet.Config file.

Configuring Global Folders with Environment Variables

Visual Studio for Mac will not use environment variables defined in the Bash profile ~/.bash_profile or the Zsh profile ~/.zprofile unless Visual Studio for Mac is run from the Terminal.

open -n "/Applications/Visual Studio.app"

When Visual Studio for Mac is run from the Dock, or from LaunchPad, it does not inherit these environment variables.

Let us take a look at how we can define these NuGet environment variables so that Visual Studio for Mac will use them without having to launch it from the Terminal.

Create the file ~/Library/LaunchAgents/environment.plist containing the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version=“1.0” encoding=“UTF-8”?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “https://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=“1.0”>
<dict>
<key>Label</key>
<string>my.startup</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>launchctl setenv NUGET_PACKAGES /Volumes/YourDrive/NuGet/.nuget/packages
launchctl setenv NUGET_HTTP_CACHE_PATH /Volumes/YourDrive/NuGet/.nuget/v3-cache
launchctl setenv NUGET_PLUGINS_CACHE_PATH /Volumes/YourDrive/NuGet/.nuget/plugins-cache</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

Replace the NuGet paths /Volumes/YourDrive/NuGet/ defined above as required.

Restart macOS to have this Launch Agent run.

After restarting you can check the environment variables are being used by NuGet by using the command line:

nuget locals all -list

Now when Visual Studio for Mac is launched from the Dock, or from LaunchPad, it will use these custom NuGet folders.

More Information

launchctl setenv defines environment variables globally so they are available to all macOS applications launched with launchd.

NuGet Support in Visual Studio for Mac 8.5

Changes

  • NuGet 5.4 support
  • Support Plugin-based NuGet Credential Providers
  • Fixed requests bypassing the native macOS HTTP handler

More information on all the new features and changes in Visual Studio for Mac 8.5 can be found in the release notes.

NuGet 5.4 support

NuGet 5.4.0.6315 is now included with Visual Studio for Mac 8.5.

Support Plugin-based NuGet Credential Providers

NuGet credential provider plugins are now supported by Visual Studio for Mac.

Plugins are self-contained executables which provide credentials for NuGet package sources. One example is the Azure Artifacts Credential Provider which Visual Studio for Mac can now use whilst it does not have integrated support for accessing packages sources available from Azure DevOps.

Bug Fixes

Fixed HTTP requests bypassing the native macOS HTTP handler

Restoring or installing a NuGet package into a project that uses PackageReferences was bypassing the native macOS HTTP handler.

This was due to NuGet’s CachingSourceProvider creating its own set of INuGetResourceProviders when it creates a set of new SourceRepository instances. This resulted in the default HttpSourceResourceProvider being used, instead of the custom one provided by Visual Studio for Mac. The default HttpSourceResourceProvider uses Mono’s HttpClientHandler not the native HTTP Client handle NSUrlSessionHandler provided by Xamarin.Mac. This would happen when the Nuget package was was downloaded.

NuGet 5.4 now supports defining custom INuGetResourceProvider factory that is used globally. This is now used by Visual Studio for Mac so all HTTP requests use the native macOS HTTP handler NSUrlSessionHandler.

NuGet Support in Visual Studio for Mac 8.4

Changes

  • Improved accessibility of the Manage NuGet Packages dialog and Add Package Source dialog
  • Fixed updating multiple NuGet packages failing due to restricted version range of a common dependency

More information on all the new features and changes in Visual Studio for Mac 8.4 can be found in the release notes.

Accessibility Improvements – Manage NuGet Packages dialog

Voice Over now recognises tabs

The Browse, Installed, Updates and Consolidates tabs are now recognised as tabs by Voice Over. Previously they were being treated as text labels and Voice Over would not announce that a tab could be selected via Control-Option-Space.

Voice Over now announces status messages

The status message that is displayed with the busy spinner image is now announced by Voice Over. When the status message is removed another message is announced by Voice Over to say the loading has completed or, if a search filter was entered, search was completed. If no packages are found when searching this message is also announced by Voice Over.

Improve Voice Over reading of Id label

The Id label has been changed to ID. Using ID allows Voice Over to announce it as I.D. instead of a single word. Note that some Voice Over voices, such as English UK, still announce the text incorrectly. Without changing the label text to be “I.D.” there does not seem to be a way of fixing this for all voices. System Preferences on the Mac can be used to change the pronounciation for certain words if required.

Voice Over now reads first column header in Consolidate tab

The check box to select a project to consolidate was in its own column that had no name. Using Voice Over it was not obvious what this check box was for. Now the check box and the project name are in the same column and Voice Over reads the column header name, the project name and the checkbox state which makes it easier to understand what the list is displaying.

Voice Over now reading associated labels for selected UI control

Labels were not associated with their corresponding UI controls which resulted in them not being read by Voice Over when corresponding UI control was selected.

The package source combo box is now read by Voice Over as ‘Package Sources’. Previously there was no associated label information being read.

Voice Over now reads the label for Search text field. The search text box now shows ‘Search’ as placeholder text.

Voice Over now reading package list information

Voice Over now reads the package information in the list and the check box can be ticked or unticked by using Voice Over. Previously no information was read by Voice Over and the check box could not be accessed.

Keyboard can now be used to move across tabs

Previously it was not possible to tab across the Browse, Installed, Updates or Consolidate tabs.

This change will be in Visual Studio for Mac 8.4.2.

Accessibility Improvements – Add Package Source Dialog

In Preferences – NuGet – Sources, the Add Package Source dialog would lose focus when the Browse button was used. A way to reproduce this is to tab to the Add button, press space, then tab to the Browse button in the Add Package Source dialog, press space, then press escape. The Add Package Source dialog then no longer has focus and tabbing does not work.

This has been fixed by explicitly setting focus back to the parent dialog when a child dialog is closed.

Bug Fixes

Fixed updating multiple NuGet packages failing due to restricted version range of a common dependency

Updating two NuGet package references that have a strict dependency on a single version of another NuGet package, not explicitly added to the project, would fail in the Manage NuGet Packages dialog. This was because the update was being done one NuGet package at a time.

With an Android project that uses Xamarin.Forms this could happen when updating Xamarin.Essentials, an Xamarin.Android.Support.Core.Utils and Xamarin.Forms at the same time. The Xamarin.Android.Support NuGet packages depend on specific versions for their dependencies which can cause the update to fail depending on whether a NuGet package is updated on its own or in a group. The resulting failure would be similar to

1
2
3
Version conflict detected for Xamarin.Android.Support.Collections. Install/reference Xamarin.Android.Support.Collections 28.0.0.3 directly to project to resolve this issue. 
 MyProject.Android -> Xamarin.Android.Support.Core.Utils 28.0.0.3 -> Xamarin.Android.Support.Compat 28.0.0.3 -> Xamarin.Android.Support.Collections (= 28.0.0.3) 
 MyProject.Android -> Xamarin.Essentials 1.2.0 -> Xamarin.Android.Support.CustomTabs 28.0.0.1 -> Xamarin.Android.Support.Collections (= 28.0.0.1).

Updating NuGet packages in the Manage NuGet packages dialog is now done as a batch instead of individually. This allows NuGet to update both NuGet packages so they then use the new strict dependency.

Note that updating all packages in the project from the Solution window does not have this problem since there the packages were already updated together in a batch.

Project System Tools for Visual Studio for Mac

The Project System Tools extension provides MSBuild design-time and build logging for Visual Studio for Mac.

Build Logging window and BinLog tree view

This is based on the Project System Tools available for Visual Studio on Windows and also re-uses code from this extension.

Features

  • Build Logging window
    • Shows a list of builds and design-time builds
  • View MSBuild log output for all builds and design-time builds
  • View MSBuild binary logs for builds
    • Build tab shows a tree view of the build results from the binary log
    • Target Summary tab shows target name, number of calls, timings and file location
    • Task Summary tab shows task name, number of calls, timings and file location

Supports

  • Visual Studio Mac 8.1 or later.

Build Logging Window

To open the Build Logging Window

  • Select View – Pads – Build Logging

Build Logging window

Click the green arrow to enable logging for builds and design-time builds.

To stop the logging click the red square.

To filter the targets use the combo box to restrict the items shown to builds or design time builds, or use the search on the right hand side of the window.

MSBuild Log Output

To open the MSBuild log output

  • Double click the row in the Build Logging window or
  • Right click the row and select Open Log File

Open Log File context menu

MSBuild Log File

The verbosity of the MSBuild log output is configured in Preferences – Projects – Build – Log verbosity.

MSBuild Binary Log

To open a binary log file

  • Right click the row in the Build Logging window and select Open Binary Log File

Note that binary logs are only available when the project or solution is built. Support for design-time build binary logs should be available in Visual Studio for Mac 8.5.

Three tabs are provided by the Project System Tools extension when a binary log file is opened.

  • Build
    • Tree view of the binary log targets and tasks
    • Properties window shows more information about the selected task or target
  • Target Summary
    • Target name
    • Source filename
    • Number of calls
    • Time taken
    • Percentage of total time taken
  • Task Summary
    • Task name
    • Source filename
    • Number of calls
    • Time taken
    • Percentage of total time taken

Build Tab

MSBuild Binary Log File - Build tab

The Build tab shows the run times of the targets and tasks, and whether they ran successfully.

Skipped tasks and targets are shown in light grey text.

Selecting a tree node in the Build tab will show more information about that node in the Properties window.

MSBuild Binary Log File - Build tab - Properties window

Target Summary Tab

MSBuild Binary Log File - Target Summary tab

Targets are shown in the order they were run and can be sorted by clicking the column headers.

Task Summary Tab

MSBuild Binary Log File - Task Summary tab

Tasks are shown in the order they were run and can be sorted by clicking the column headers.

Project System Tools Installation

The Project System Tools extension is available from the Visual Studio for Mac extensions repository. To install the addin:

  • From the main menu, open the Extensions Manager dialog.
  • Select the Gallery tab.
  • Expand IDE extensions.
  • Select Project System Tools
  • Click the Refresh button if the extension is not visible.
  • Click Install… to install the extension.
  • Restart Visual Studio for Mac.

Links

NuGet Support in Visual Studio for Mac 8.3

Changes

  • NuGet 5.3 support
  • Managing NuGet packages for the solution
  • Show NuGet package updates for SDK style projects in the Solution window

More information on all the new features and changes in Visual Studio for Mac 8.3 can be found in the release notes.

NuGet 5.3 support

NuGet 5.3.0.6192 is now included with Visual Studio for Mac 8.3.

Managing NuGet Packages for the solution

Support for managing NuGet packages for the solution was originally available in a separate NuGet extensions addin. This feature has now been integrated into Visual Studio for Mac, along with some user interface changes, and is now available by default.

Manage NuGet Packages - Solution - Browse tab

The NuGet extensions addin is still available and provides a NuGet Powershell Console but it no longer includes a Manage NuGet Packages dialog.

The Manage NuGet Packages dialog contains four tabs:

  • Browse
    • Used to search for and install NuGet packages. This is equivalent to the old Add NuGet Packages dialog.
  • Installed
    • Shows the installed NuGet packages. NuGet packages can be uninstalled from this tab.
  • Updates
    • Shows NuGet packages that have new versions available.
  • Consolidate
    • Shows NuGet packages that have multiple versions installed in the solution. This is only available when managing NuGet packages for the solution.

The Add Packages dialog has been removed and replaced with the Manage NuGet Packages dialog since everything that was supported with the Add Packages dialog is available the new dialog.

To manage the NuGet packages for the solution the Manage NuGet Packages dialog can be opened in the following ways:

  • Right click the solution in the Solution window and select Manage NuGet Packages…
  • From the main menu select ProjectManage NuGet Packages…

The Manage NuGet Packages dialog title is different depending on whether the NuGet packages are being managed for the solution or for the project. When managing packages for the solution the dialog title will be Manage NuGet Packages – Solution.

Managing NuGet Packages for a single project

To manage NuGet packages for a single project the Manage NuGet Packages dialog can be opened in the following ways:

  • Right click the project in the Solution window and select Manage NuGet Packages…
    • This was added to make Visual Studio for Mac consistent with Visual Studio on Windows
  • Double click the Packages folder in the Solution window
  • Right click the Packages folder and select Manage NuGet Packages…
  • Double click the Dependencies folder in the Solution window.
    • In previous versions of Visual Studio for Mac this would not open the dialog
  • Right click the Depdendencies folder and select Manage NuGet Packages..
  • Double click the NuGet folder underneath the Dependencies folder
  • Right click the NuGet folder, underneath the Dependencies folder, and select Manage NuGet Packages…

When managing NuGet packages for a single project the dialog title shows the project name Manage NuGet Packages – ProjectName.

Manage NuGet Packages for Project

Installing NuGet Packages

The Browse tab in the Manage NuGet Packages can be used to search for and install NuGet packages into one or more projects. This tab is equivalent to the old Add NuGet Packages dialog.

The latest stable NuGet package version is now indicated by having (latest stable) appended on the right hand side of the dialog.

To install a NuGet package into multiple projects:

  • Right click the solution and select Manage NuGet Packages…
  • Search for a NuGet package
  • Click the Add Package button
  • In the Select Projects dialog that is opened, select the projects that you want the NuGet package to be installed, and click OK

Manage NuGet Packages - Select Projects dialog

Uninstalling NuGet Packages

The Installed tab in the Manage NuGet Packages can be used to uninstall NuGet packages from one or more projects.

Manage NuGet Packages - Installed tab

To uninstall a NuGet package:

  • Right click the solution and select Manage NuGet Packages…
  • Select the Installed tab
  • Select a NuGet package to uninstall
    • To uninstall multiple NuGet packages use the check boxes in the package list
  • Click the Uninstall Package button
  • In the Select Projects dialog that is opened, select the projects where the NuGet package should be removed, and click OK.

Updating NuGet Packages

The Updates tab shows the updated NuGet packages available to be installed.

Manage NuGet Packages - Updates tab

The Updates tab shows the Current Version of the NuGet package installed on the right hand side of the dialog. If multiple versions of the packages are installed across the solution, then this will display Multiple with an information icon where information about the projects and versions can be viewed in a tooltip.

Manage NuGet Packages - Updates tab -  Multiple versions installed

Manage NuGet Packages - Updates tab -  Multiple versions installed - tooltip

To update a NuGet package in multiple projects:

  • Right click the solution and select Manage NuGet Packages…
  • Select the Updates tab
  • Select a NuGet package to update
    • To update multiple NuGet packages use the check boxes in the packages list
  • Click the Update Package button
  • In the Select Projects dialog that is opened, select the projects where the NuGet package should be updated, and click OK.

Consolidating NuGet Packages

If there are different versions of a NuGet package installed in the solution the Consolidate tab will show this and allow the packages to be consolidated to a particular version.

Manage NuGet Packages - Consolidate tab

When a NuGet package is selected, the right hand side of the dialog shows all the projects in the solution. The project will be checked if it has the selected package installed. The package version used by the project is also shown. Projects that have a package to consolidate are shown first in the list.

Note that the Consolidate tab is only displayed if NuGet packages are being managed for the solution.

By default the Consolidate tab will select the latest version available from the current NuGet package source. This may be different from the latest version installed in the projects.

To Consolidate a NuGet package:

  • Right click the solution and select Manage NuGet Packages…
  • Select the Consolidate tab
  • Select the NuGet package you want to consolidate.
    • Use the check box next to the NuGet package if you want to consolidate multiple NuGet packages at the same time
  • Check or uncheck the projects in the projects list.
    • By default projects that contain the selected NuGet package will be checked
  • Click the Consolidate Package button.

Show NuGet package updates for SDK style projects in the Solution window

NuGet package updates are now shown in the Solution window for SDK style projects.

SDK style project - package updates - solution window

If an updated package is available this information will now be shown on the Dependencies folder, the NuGet folder, and the top level package in the Solution window.

Previously NuGet package updates were only displayed for projects that used a packages.config file or for non-SDK style projects that used PackageReferences.

Instead of showing the updated NuGet package version text, next to the installed version in the solution window, an update icon is displayed with the version information available in a tooltip. This prevents the version information taking up a lot of space to the right, which can happen for long version numbers.

SDK style project - package update version tooltip - solution window

The Update menu, when right clicking a NuGet package, now shows the version for the update. Otherwise the Update menu is displayed.

SDK style project - update menu item - solution window

If there is an update and a NuGet warning only the warning icon will be displayed with the warning message available in the tooltip. The update information will only be available in the right click context menu for the NuGet package in this case.

Package versions are now displayed in solution window for non-SDK style projects.

Non-SDK style project - package updates - solution window

SDK style projects always displayed the package version in the Solution window but non-SDK style projects did not. To make these consistent the NuGet package version is now shown in the Solution window for all project types.

Previously for non-SDK style projects the package version was shown as a menu item when right clicking a NuGet package. This has been removed since the package version is now displayed next to the package id in the Solution window.

Bug Fixes

Fixed text colour when row selected in Manage NuGet Packages dialog

When a package was checked in the Add NuGet Packages dialog any row that was selected would display black text instead of white text. This was hard to read with the blue background colour used for the selected row. The wrong text colour was being set when a package was checked. This has been fixed in the Manage NuGet Packages dialog.

NuGet Support in Visual Studio for Mac 8.2

Changes

  • NuGet 5.1 support
  • Support partial installs into multi-target framework projects
  • Fixed no network error displayed in Add Packages dialog
  • Fixed restoring too many projects when target framework changed
  • Fixed adding non-sdk style project triggering NuGet restore multiple times
  • Fixed restore menu incorrectly disabled

More information on all the new features and changes in Visual Studio for Mac 8.2 can be found in the release notes.

NuGet 5.1 support

NuGet 5.1.0.6013 is now included with Visual Studio for Mac 8.2.

Support partial installs into multi-target framework projects

A NuGet package being installed into a multi-target framework project may not support all frameworks. When this happens the PackageReference will now be added with a condition so the NuGet package is not used for frameworks that are not supported.

1
2
3
4
5
6
7
8
9
10
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net472;netstandard1.2</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'net472'">
    <PackageReference Include="EntityFramework" Version="6.2.0" />
  </ItemGroup>
</Project>

Bug Fixes

Fixed no network error displayed in Add Packages dialog

Networking errors were not being reported in the Add Packages dialog resulting in no information being available explaining why there were no search results.

Visual Studio for Mac uses Xamarin.Mac’s NSUrlSessionHandler for HTTP requests and the NSUrlSessionHandler reports errors using curly braces. For example:

1
2
[nuget.org] The Internet connection appears to be offline.
  Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={NSUnderlyingError=0x7fce42892a80 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=https://api-v2v3search-1.nuget.org/query?q=&skip=0&take=26&prerelease=false&supportedFramework=Xamarin.iOS,Version=v1.0&semVerLevel=2.0.0, NSErrorFailingURLKey=https://api-v2v3search-1.nuget.org/query?q=&skip=0&take=26&prerelease=false&supportedFramework=Xamarin.iOS,Version=v1.0&semVerLevel=2.0.0, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=50, NSLocalizedDescription=The Internet connection appears to be offline.}

This text was then being passed to string.Format in the Add Packages dialog and was causing a FormatException. The error would then not be displayed in the Add Packages dialog. The text now has the curly braces escaped to prevent the FormatException.

Fixed restoring too many projects when target framework changed

When the target framework was changed in a SDK style project all SDK style projects in the solution were restored. Now only the project and projects that depend on it are restored.

Fixed adding non-sdk style project triggering NuGet restore multiple times

Adding a new non-sdk style project to a solution could cause a NuGet restore to run multiple times.

The problem was that the SDK style projects, such as those that target Xamarin.Mac, may change their target framework on re-evaluation. This was causing Visual Studio for Mac to run a restore for all SDK style projects in the solution, multiple times. To avoid this the target framework changes during re-evaluation are ignored.

Fixed restore menu incorrectly disabled

In the Solution window on right clicking a solution, or the packages folder, the restore menu was incorrectly disabled when an SDK style project targeted .NET Framework or when the project had its RestoreProjectStyle set to PackageReference and had no PackageReferences.

LibMan support in Visual Studio for Mac

The Library Manager addin provides Microsoft Library Manager (LibMan) support for Visual Studio for Mac. LibMan provides a way to install third-party client-side JavaScript libraries for ASP.NET Core and ASP.NET projects.

Features

  • Add Client-Side Library dialog
  • Restore client-side libraries
  • Deleting client-side libraries
  • Automatic client-side library restore on saving libman.json file

Full text editor support is not currently available. The following text editor quick actions are not supported:

  • Uninstall a client-side library
  • Check for client-side library updates

Supports

  • Visual Studio Mac 8.1 or later.
  • ASP.NET Core and ASP.NET projects

Add Client-Side Library Dialog

To open the Add Client-Side Library dialog, right click the project, or a folder, and select Add – Client-Side Library.

Add - Client-Side Library menu

Add Client-Side Library dialog

The library provider can be selected from the Provider list.

Typing in the Library text field will search the library provider and show a list of matching libraries.

Add Client-Side Library dialog completion list

Pressing tab or return will insert the selected library from the completion list into the Library text field.

You can then choose to include all the client-side library files or a selection of those files.

Add Client-Side Library dialog select files

The Target Location indicates where the client-side library files will be installed.

Clicking the Install button will create a libman.json file and install the client-side library into your project.

jQuery installed into project

More detailed information about the client-side library installation is available by clicking the status bar or by selecting View – Pads – Library Manager Output.

Library Manager Output window

Adding a libman.json file

To add a libman.json file without using the Add Client-Side Library dialog, right click the ASP.NET project and select Manage Client-Side Libraries.

Manage Client-Side Libraries menu

This will create a libman.json file and open it in the text editor.

libman.json file in text editor

Restoring Client-Side Libraries

To restore the client-side libraries you can right click the libman.json file in the Solution window and select Restore Client-Side Libraries.

Restore Client-Side Libraries menu

Information about the restore operation is available from the Library Manager Output window.

Alternatively saving the libman.json file in the text editor will run a restore.

Restore errors are displayed in the Errors window and in the libman.json file if it is open in the text editor.

LibMan restore error

Deleting Client-Side Libraries

To remove the client-side libraries you can right click the libman.json file in the Solution window and select Clean Client-Side Libraries.

Clean Client-Side Libraries menu

This will delete the client-side libraries from the project.

Library Manager Addin Installation

The Library Manager addin is available from the Visual Studio for Mac extensions repository. To install the addin:

  • From the main menu, open the Extensions Manager dialog.
  • Select the Gallery tab.
  • Expand IDE extensions.
  • Select the Library Manager addin
  • Click the Refresh button if the addin is not visible.
  • Click Install… to install the addin.
  • Restart Visual Studio for Mac.

Links

NuGet Support in Visual Studio for Mac 8.1

Changes

  • NuGet 5.0 support
  • Fixed PackageReference metadata not added for development dependencies
  • Fixed DotNetCliToolReferences not being restored
  • Fixed Multiplatform Library build error with Android projects

More information on all the new features and changes in Visual Studio for Mac 8.1 can be found in the release notes.

NuGet 5.0 support

NuGet 5.0.2.5988 is now included with Visual Studio for Mac 8.1.

Bug Fixes

Fixed PackageReference metadata not added for development dependencies

Installing a NuGet package that is a development dependency, such as GitInfo, would not add the PrivateAssets nor the IncludeAssets metadata to the PackageReference. This is now supported and mirrors the behaviour of ‘dotnet add package’ and Visual Studio on Windows.

Fixed DotNetCliToolReferences not being restored

DotNetCliToolReferences are available in the package dependency graph but are treated as separate projects in this graph. Since these did not map to an existing project in the solution they were not added to the full dependency graph which resulted in these tools not being restored.

DotNetCliToolReferences are only restored when the entire solution is restored. Restoring a single project only restores the project itself not the dotnet cli tool project referenced by the project.

MSBuild supports restoring DotNetCliToolReferences in any project type that uses PackageReferences so Visual Studio for Mac also supports this.

Fixed Multiplatform Library build error with Android projects

When generating a Portable Class Library (PCL) assembly from the intersection of project assemblies the ApiIntersect build task would throw an exception since it could not resolve the Mono.Android assembly. This problem has been fixed in a more recent NuGet.Build.Packaging where the failure to resolve has been converted to a warning.

1
2
3
4
5
6
7
8
9
10
System.Exception: Could not resolve Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
    at ApiIntersect.FrameworkAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x0001b] in <aac3e0d5bcd4473a96e385115da49b96>:0
    at ApiIntersect.FrameworkAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <aac3e0d5bcd4473a96e385115da49b96>:0
    at ICSharpCode.Decompiler.Ast.Transforms.IntroduceUsingDeclarations.Run (ICSharpCode.NRefactory.CSharp.AstNode compilationUnit) [0x00142] in <37b5ad8a7a94479fbc5b574a8fc6281a>:0
    at ICSharpCode.Decompiler.Ast.Transforms.TransformationPipeline.RunTransformationsUntil (ICSharpCode.NRefactory.CSharp.AstNode node, System.Predicate`1[T] abortCondition, ICSharpCode.Decompiler.DecompilerContext context) [0x0002c] in <37b5ad8a7a94479fbc5b574a8fc6281a>:0
    at ICSharpCode.Decompiler.Ast.AstBuilder.RunTransformations (System.Predicate`1[T] transformAbortCondition) [0x00000] in <37b5ad8a7a94479fbc5b574a8fc6281a>:0
    at ICSharpCode.Decompiler.Ast.AstBuilder.RunTransformations () [0x00000] in <37b5ad8a7a94479fbc5b574a8fc6281a>:0
    at ApiIntersect.MainClass.DumpTypes (System.Collections.Generic.List`1[T] types, System.String baseDir) [0x000a7] in <aac3e0d5bcd4473a96e385115da49b96>:0
    at ApiIntersect.MainClass.Process (System.Collections.Generic.List`1[T] intersections, System.Collections.Generic.List`1[T] exclusions, Mono.Cecil.ReaderParameters readerParameters, System.String outputPath) [0x00319] in <aac3e0d5bcd4473a96e385115da49b96>:0
    at ApiIntersect.MainClass.Main (System.String[] args) [0x0039f] in <aac3e0d5bcd4473a96e385115da49b96>:0

An updated NuGet.Build.Packaging has not been published to nuget.org so only new projects created with Visual Studio for Mac will get the NuGet package containing the fix.

NuGet PowerShell Core Console in Visual Studio for Mac 8.0

The NuGet extensions addin now includes a PowerShell Core based NuGet Package Manager console for Visual Studio for Mac 8.0.

NuGet Package Manager Console window

A NuGet PowerShell console has been available with the NuGet extensions addin since Xamarin Studio 5.0. Previously it used Pash, a cross-platform, open source reimplementation of PowerShell. Pash is no longer being actively developer on after Microsoft released PowerShell Core. The PowerShell support in Pash was incomplete, so whilst the NuGet commands, such as Install-Package, were supported, more complicated commands, such as those provided by Entity Framework Core, were not supported. Moving to PowerShell Core provides full PowerShell support, and with a partial implementation of the Visual Studio EnvDTE API, Entity Framework Core commands are now supported.

The NuGet extensions addin runs a .NET Core console application that hosts PowerShell Core. Communication between the addin running in Visual Studio for Mac and the console application is through the StreamJsonRpc library.

New Features

The following lists the new features compared with the Pash based PowerShell console.

  • PowerShell Core based NuGet Package Manager Console
    • Full PowerShell support
    • Get-Help now supported
  • Support for Entity Framework Core NuGet commands
  • Tab completion
  • Support for stopping the executing command
  • Opening the NuGet package source configuration page from the console

Limitations

  • Visual Studio EnvDTE API implementation is incomplete

The Visual Studio EnvDTE API is partially implemented. Whilst Entity Framework Core is supported other PowerShell scripts included with NuGet packages may not work.

  • Password protected NuGet package sources not supported in the following PowerShell commands:

    • Find-Package
    • Get-Package

Note that the other NuGet PowerShell commands are supported.

The NuGet extensions addin will not send usernames and passwords to the PowerShell Core host console application. .NET Core also does not support decrypting passwords stored in the NuGet.Config file.

The Find-Package and Get-Package commands all run completely within PowerShell hosted in the .NET Core console application.

The other commands work since they run partially within Visual for Mac where actions involving password protected NuGet package sources are supported.

  • Requires .NET Core 2.1 SDK to be installed

Opening the NuGet Package Manager Console window

From the View menu, select Pads, then select NuGet Package Manager Console.

View - Pages - NuGet Package Manager Console menu

 Entity Framework Core Support

The PowerShell commands provided by the Microsoft.EntityFrameworkCore.Tools NuGet package are supported in .NET Core projects.

  • Add-Migration
  • Drop-Database
  • Get-DbContext
  • Remove-Migration
  • Scaffold-DbContext
  • Script-Migration
  • Update-Database

Package Manager Console - Entity Framework Core Add-Migration and Update-Database commands

Note that the Entity Framework Core commands are not currently supported in projects that target the .NET Framework. This is because the PowerShell commands attempt to directly run ef.exe that is included in the NuGet package instead of using the .NET Core ef.dll which is used with projects that target .NET Core.

Tab Completion

Pressing tab in the console window will try to auto-complete the command being typed in.

Tab completion - Install-Package Newtonsoft.Json

Tab completion - Install-Package Newtonsoft.Json -Version

If there is only one match on pressing tab then the text will be inserted.

If there are multiple possible matches then a window will be displayed allowing an item to be selected by pressing Tab, Enter or Return. Typing with this completion list window open will filter the items in the list.

Stopping the PowerShell command being run

When a PowerShell command is being run the Stop button is enabled. The Stop button is the last button on the top right of the NuGet Package Console window.

Package Manager Console stop button

Clicking this button will attempt to stop the PowerShell command being run.

Package Manager Console pipeline stopped

Opening the NuGet Package Console configuration page

At the top of the NuGet Package Console window there is a cog icon after the list of package sources.

Package Manager Console configure sources cog icon

Clicking this cog icon will open the NuGet Package Sources configuration page which is also available from Preferences – NuGet – Sources.

Installation

The NuGet extensions addin is available from the Visual Studio for Mac extensions repository. To install the addin:

  • From the main menu, open the Extensions Manager dialog.
  • Select the Gallery tab.
  • Expand IDE extensions.
  • Select NuGet Package Management Extensions 0.18 or later.
  • Click the Refresh button if the addin is not visible.
  • Click Install… to install the addin.
  • Restart Visual Studio for Mac.