How to find and use downloaded packages from nuget in vs2017 software (and in an asp.net core project)? - asp.net-core

In Visual Studio 2017, I use the following command to install a package like .jQuery.Unobtrusive.Validation:
Install-Package Microsoft.jQuery.Unobtrusive.Validation -Version 3.2.11
And the operation is done successfully.
Now I'm looking for files on wwwroot but can not find anything? what is the problem?

Use LibMan :
In Solution Explorer, right-click the project folder in which the files should be added. Choose Add > Client-Side Library.
Type jquery-validation-unobtrusive#3.2.11 in Library input area .
Click Install , the library will install to target location . The default is wwwroot/lib/jquery-validation-unobtrusive/

Related

Cannot build .net core 1.1 with msbuild tools

I have a .net core class library I am attempting to build into a nugget package. however, on my build server (running team city), I am getting the following error:
C:\TeamCity\buildAgent\work\3c6531587491c25e\MySolution\MyProject.csproj
error MSB4019: The imported project "C:\Program Files (x86)\Microsoft
Visual
Studio\2017\BuildTools\MSBuild\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
When I look in this directory, I ma missing the "Microsoft.NET.Sdk" folder from my build server. where do I get these tools without having to install visual studio?
Thanks!
See the tracking issue on GitHub: https://github.com/Microsoft/msbuild/issues/1697
If you don't want to touch your build tools installation (by copying SDK files), you can also set the MSBuildSDKsPath environment variable to the location of the SDKs carried in the .net CLI (usually C:\Program Files\dotnet\sdk\1.0.0\Sdks\)

Creating a nuget package containing a custom build step for .NET Core

Is it possible to create a nuget package containing a custom build step (analyzing the generated assembly and automatically generating some metadata)? The target environment should be .NET Core with the new .csproj format (Currently using Visual Studio 2017 RC). Best case would be if this only adds a msbuild step and no dependency to the projects resulting assembly.
If seen that it should be possible with full .NET, but the documentation for msbuild and the new .csproj for .NET Core is a bit sparse at the moment.
You can add MSBuild targets to a NuGet package in the "build" folder. The targets or props file name must match the package ID. When installed via "PackageReference" or packages.config, NuGet will automatically import the targets/props file into the csproj, so these files must be written as valid MSBuild code.
i.e. if your package was named "MyClassLibrary", you could have the following layout:
(package root)
lib/
netstandard1.3/
MyClassLibrary.dll
build/
netstandard1.3/
MyClassLibrary.props
MyClassLibrary.targets
For example, see Microsoft.Extensions.Configuration.UserSecrets on NuGet.org or and its source code on GitHub. This package uses an MSBuild target to automatically generate an assembly attribute before the compilation step
Nuget may execute "init.ps1" powershell script during installation if find it in your nuget package. But keep attention, that script support was modified in Nuget 3.x:
In Nuget 3.xx Powershell script support was modified to no longer execute install and uninstall scripts (install.ps1, uninstall.ps1), but init scripts are still executed.
Additionally, running NuGet outside of Visual Studio at the command-line or on other operating systems cannot execute these Powershell scripts as they relied on Visual Studio automation. Powershell is in NuGet to provide a shim to allow for missing features to run inside of Visual Studio
Powershell script support was modified to no longer execute install and uninstall scripts, but init scripts are still executed.
You can find more here in "Powershell Install and Uninstall Scripts".

Building Xamarin Android on TFS - how to download Nuget packages

I have a Xamarin Android project that I'm building on a TFS build server. The Nuget packages are not restored, and so the build fails with a bunch of "[filename] could not be found" errors.
I believe the problem is that for the Android build, you specify the .csproj file, rather than the .sln. The field is called "Project" on a Xamarin.Android build step. The automatic Nuget package restore only works if you load the solution file. If you directly build the csproj with MSBuild.exe, the Nuget package restore does not happen.
I expect I can create a PowerShell script step that manually calls Nuget, but it seems this should be supported first-class. Any ideas for me?
The recommended way is to add a NuGet Installer build step before the actually build step. More about this package here

Visual Studio Online build error about NuGet client version (v3.0 or above required)

I am trying to setup a CI build using Visual Studio Online but I am getting the following error about the NuGet client:
The 'System.Net.Http 4.0.0' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.
Solution builds and deploys fine directly from my Visual Studio 2015 itself but I am unable to get it to build in VSO. Does anyone if NuGet 3.x is installed on hosted build controllers or if I can supply my own copy along with my solution?
It's hard to guess by the question what build tasks are used. If you use VSBuild/MSBuild, it is only possible to turn "Restore NuGet packages" on, but there's no influence on the NuGet version.
However, if you turn this checkbox off, and instead add another build task called NuGet Installer before the main build step, you'll be able to provide a custom path to NuGet.exe. In the case of hosted build agent, the most obvious option is to commit required version of NuGet.exe to the repo, and then reference it from the build step:
Sounds like a hack, but it might work in your case.

VisualStudio.com (Visual Studio Team Services) builds failing on nuget package dependencies

Thought I would try and get the most out of my visualstudio.com trial membership. I created a solution with a few projects, pushed it to the Microsoft git source control provider, configured a build definition and tried to build it on the project server. However it keeps failing telling me:
The type or namespace name 'Moq' could not be found (are you
missing a using directive or an assembly reference?)
I know this means that the build server can't find the Moq.dll library. I had installed it using NuGet, but configured my .gitignore to keep the packages folder out of source control. I also enabled NuGet package restore for the solution and pushed nuget.exe, nuget.targets, and nuget.config (all 3 of the files in the .nuget folder) along with all of the other project files.
Now I am sure I could get the build to work if I pushed the packages folder too, but I want to keep the nuget packages folder out of source control. So I am wondering, is this possible? The visualstudio.com docs say that the build servers have visual studio 2013 installed, and because of this I assume that nuget package restore would work to download the missing dll's so that they can be resolved by MSBuild. Is this right? Or to use automated CI builds at visualstudio.com, do you need to have your packages under source control?
According to the log file, nuget package restore downloaded the package. What gives?
Project "C:\a\src\MySln.sln" (1) is building
"C:\a\src\Tests\MySln.ProjA.UnitTests\MySln.ProjA.UnitTests.csproj"
(3) on node 1 (default targets). RestorePackages:
"C:\a\src.nuget\NuGet.exe" install
"C:\a\src\Tests\MySln.ProjA.UnitTests\packages.config" -source ""
-NonInteractive -RequireConsent -solutionDir "C:\a\src\ " Restoring NuGet packages... To prevent NuGet from downloading packages during
build, open the Visual Studio Options dialog, click on the Package
Manager node and uncheck 'Allow NuGet to download missing packages'.
All packages listed in packages.config are already installed.
PrepareForBuild: Creating directory "obj\Debug\".
ResolveAssemblyReferences: Primary reference "Moq". C:\Program Files
(x86)\MSBuild\12.0\bin\amd64\Microsoft.Common.CurrentVersion.targets(1635,5):
warning MSB3245: Could not resolve this reference. Could not locate
the assembly "Moq". Check to make sure the assembly exists on disk. If
this reference is required by your code, you may get compilation
errors.
[C:\a\src\Tests\MySln.ProjA.UnitTests\MySln.ProjA.UnitTests.csproj]
This line is also in the build log file, below the above:
Considered "..\packages\Moq.4.1.1311.0615\lib\net40\Moq.dll", but it didn't exist.
I had this same error but it was occurring on our build server. I had added Moq via NuGet, checked in the project and everything was fine. I then moved the project into a new folder in TFS and the build server just couldn't seem to find Moq. It was building great locally. I ended up fixing the problem by making sure all of my changes were checked into source control and then deleting my local source code directory. I got latest and my test project realized it needed a new copy of Moq. I blame TFS/ source safe or what ever the Visual Studio integration module is for not adding it to source control at some point in time.
Figured this one out on my own. Turns out I had added the nuget packages before moving the test project into a Tests subfolder. The solution still built on my LM, probably because the dependencies were already copied to bin/Debug. After reinstalling the nuget packages, the solution built on vs.com.