package file from packagerefernce - visual-studio

We are using appveyor as CI CD tool to build and deploy our website. Currently in my yaml file i have following code
- 7z a MyTest.zip .\MyProj\MyProj.Test\bin\* .\MyProj\packages\NUnit.ConsoleRunner.3.9.0\tools\*
This used to work fine. We changed project structure in visual studio to use new 2017 SDK .net core style. Now packages folder is not available and it now uses packagereference.
So now it complains on this line in yaml saying specified path not found
.\MyProj\packages\NUnit.ConsoleRunner.3.9.0\tools\*
So now how can i package this file?

Packages installed via PackageReference will now be found at %userprofile%\.nuget\packages instead of within the project directory, so change your 7z call accordingly.

Related

Test NuGet package Installation on C# project in Azure Pipeline

Is it possible, as part of a CI process for NuGet package creation, to install a newly created package to a project, residing in the repository? So that the installation can be tested.
It's easy to do using Visual Studio UI, but how to do it on a newly created azure pipeline worker automatically?
Install NuGet package on the project in Azure Pipeline
I am afraid it is impossible to install NuGet package on the project in Azure Pipeline.
Because NuGet CLI install command line just Installs a package into the current project but does not modify projects or reference files (packages.config).:
It is like the command line nuget restore, just download the packages not install it.
To install the package to the project, we need modify the project file via access to visual studio objects:
https://github.com/NuGet/Home/issues/1512
So it should be impossible to install NuGet packages out of Visual Studio, check my another thread for some details.
Besides, we also do not recommend to install NuGet package in Azure Pipeline. If we install a newly created package to a project automatically, it will use the scripts to modify our Repos, which is not recommended and safe.
Personally, the correct process is:
Create the new package in the Azure pipeline.
Publish the new package to the Artifacts or any other nuget feed.
Install/Update the new package to the project with Visual Studio and test it.
Update the new package version to the Repos.
Hope this helps.
The NuGet.Client repo has a bunch of tests that install packages into test projects and assert various things. I know of a whole lot of PackageReference tests, but can't remember any packages.config tests. Using the .NET CLI it's easy to script a lot of it, but depending on what you want to do, you might need to write some code to manipulate XML files.
Here's a bunch of useful commands totally written from memory and therefore might not work as is, but it'll get you started:
# create a new .NET Core console app. You'll need to edit the csproj to test different frameworks
dotnet new console
# create nuget.config file
dotnet new nugetconfig
# add a local folder as a package source
nuget sources add -configfile nuget.config -name local -source ..\newPackages
# set the global packages folder to a empty/temporary directory, so the test package
# doesn't pollute the agent's global packages folder
nuget config set -configfile nuget.config globalPackagesFolder gpf
# add the latest version of the package to the project in the current directory.
# use --version to specify a version
dotnet add package MyTestPackage
Since SDK style projects are so short and simple, you may be better off just hardcoding the contents in your code and write them to disk for your tests. It's what we (NuGet.Client) do.
We have plans to eventually move the config options to the dotnet cli so that you won't need to download nuget.exe, but it's really low priority since it's so easy to workaround. nuget.exe works on mono on Linux and Mac, or just hardcode the conents of the config in a string in your test and write it at runtime.
This will only be useful for you if the things you want to test are not impacted by package compatibility issues with PackageReference vs packages.config. However, given the future of .NET is SDK style projects, and SDK style projects don't support packages.config, you can try justifying it by saying it's the future.

How to push an update to a NuGet feed for .NET Framework and .NET Core libraries

I have my own NuGet feed in Azure Artefacts. Currently, there are two packages in the feed:
INTLConfiguration.Client [Version 1.0.0]
INTLConfiguration.NetFramework.Client [Version 1.0.0]
The top one is a .NET Core library and the bottom one is a .NET Framework library.
I need to push an update to the NuGet feed for both versions to be 1.0.1 - but I'm having some trouble doing this. I packed 'INTLConfiguration.Client' and renamed the .nukpg from INTLConfiguration.Client.1.0.0.nupkg to INTLConfiguration.Client.1.0.1.nupkg and tried to push the nuget to my source feed but it errored with a conflict message saying v1.0.0 already exists.
How do I go about updating both of these nuget packages into my source feed?
Thank you.
I packed 'INTLConfiguration.Client' and renamed the .nukpg from
INTLConfiguration.Client.1.0.0.nupkg to
INTLConfiguration.Client.1.0.1.nupkg
It seems that your update is just to rename the output xxx.nupkg. It's not the valid way to create updated .nupkg. A xx.nupkg is something like a .zip. Renaming it from Name.nupkg to Name.zip and then you can unzip it and see its content. Open the ProjectName.nuspec and you can find the version defined in it is still 1.0.0.
My guess:
Maybe the way you use to pack is something like creating a .net core project and right-click the pack button which outputs a ProjectName.1.0.0.nupkg.
1# If so, the easiest way to resolve it is right-click Project name in Solution Explorer=>Properties and change the Package version there:
Change the version to 1.0.1 and pack it again.
2# Also we can use .nuspec file defined by us for this option.
Add a text file to the project and rename it to xxx.nuspec. Change its build action in property window to content.
Right-click the project=>unload the project=>edit the xxx.csproj file.
Add a script like below into it:
<PropertyGroup>
<NuspecFile>NuspecName.nuspec</NuspecFile>
</PropertyGroup>
Then reload the project, every time when we use Pack option it will call NuspecName.nuspec file.
To create a nuget package by command-line, I suggest you use dotnet.exe or nuget.exe.
For your .net core project, you can use dotnet pack command.Some details about it see here.
3# To create a .net core package with version 1.0.2 without using a .nuspec file:
Open cmd.exe, and type command: cd C:\PathToProjectFolder to navigate to ProjectDir(where exists xx.csproj)
Then type command like dotnet pack -p:PackageVersion=1.0.1 to create a really version-1.0.1 nuget package. (If you only have one .csproj in the dir)
Or you need to specify the .csproj like: dotnet pack ~/projects/app1/project.csproj -p:PackageVersion=1.0.1
4# To create a .net core package with version 1.0.2 using a .nuspec file:
Create a .nuspec file and modify its content to meet your needs(Version, AuthorName...).
Open cmd.exe and use a command like:dotnet pack ~/projects/app1/project.csproj /p:NuspecFile=~/projects/app1/project.nuspec /p:NuspecBasePath=~/projects/app1/nuget
If you use the Pack option(Right-click project=>Pack button) in VS, check 1# or 2#.
If you use command-line, you can check 3# or 4#. Hope it helps:)
Update:
How do I go about updating both of these nuget packages into my source
feed?
You can check this tutorial to create a package which targets .net framework.And update the version in .nuspec before you pack it. Also, if you want to get an updated nuget package, I suggest you update the assembly version and file version for the dll itself also.

Nuget Problems Downloading Scripts

Ok, this has happened before, I'm not sure what the deal is.
I go to install this nuget package-
Microsoft.jQuery.Unobtrusive.Ajax
the package is installed "correctly" both using the command line and the GUI. But there is no scripts added to my project?
I had the same problem with MVC6 Grid. At least there I could hack the scripts in.
I found the actual script on Microsoft's CDN page so I can work around this...just wondering if I'm missing something.
Using Visual Studio 2017 and the Project is a Core 2.0 MVC project if that helps. Thanks.
the package is installed "correctly" both using the command line and the GUI. But there is no scripts added to my project?
Since the usage of NuGet for css/javascript libraries is discouraged. You should use Bower or the npm (Node Package Manager) to add the JavaScript libraries instead of using NuGet. The newer project file formats, PackageReferences, only supports files that are in a contentFiles directory inside the NuGet package.
To use the package Microsoft.jQuery.Unobtrusive.Ajax to the .net core project, you need to select your MVC project and add a new file to the project root. While in the template manager (Add->New Item...), search for "Bower Configuration File" or "npm Configuration file".
Then edit the file and add your dependency, i.e.
package.json (npm) or bower.json:
"dependencies": {
"jquery-ajax-unobtrusive": "3.2.4"
}
Note: For package.json (npm), once you save, the file will be downloaded in a directory named "node_modules`. This alone won't be enough, as the required files need to be copied over to wwwroot folder, where they can be accessed when the application runs.
For the detailed info, see NPM, BOWER, NUGET, GULP – The Four Horsemen of ASP.NET CORE Apps.

Nuget package manager console - Package does not contain a manifest

I suddenly get this error on every package I try to update/reinstall in my project.. How can I start to debug this problem? Does the package manager create a log file with more details than this? Where is the manifest that it does not find?
Same package in different project but same solution works fine.
I m having the same issue.I think it might be a nuget version issue.I tried to install the package at my visual studio 2013, with nuget version is 2.12.0.817 and i got the same error. Then i tried installing the same package at my visual studio 2015, running nuget version 3.4.4.1321 and the package got installed successfully. So if i were you i would check my nuget version.
I faced two different problems:
the tool used to compress the folder (like Compress-Archive)
adds the root folder name inside the compressed file
https://github.com/PowerShell/PowerShell/issues/14312
the tool used to compress the folder has a compression method incompatible
with the client trying to unzip the .nupkg file.
For example, in my case the System.IO.Compression.ZipFile class used to compress the content of the folder was incompatible with the client extraction capabilities.
However, when I manually compressed the same folder content
with Right-click\Send To\Compressed (Zipped) Folder, it was working fine.

How do I create a NuGet package from a project file so it includes the necessary assemblies?

To generate a NuGet package I'm currently using the command:
nuget pack project.csproj -Prop Configuration=Release
which I expected would package up the files in the bin\Release folder, i.e. the result of building the project. This folder has several MB of assemblies, however the nupkg file that gets created is only 7kb, which doesn't seem to include any of these files.
I'm running the nuget command from TeamCity so I'm trying to avoid manually editing a nuspec file.
What is the best way to package a project like this using NuGet?
TeamCity 7.0 is finally here and it has its own NuGet server built in.
You can simply ask it to take care of your packages whether you want to publish it locally or/and to nuget.org
TeamCity and NuGet

Resources