nuget pack ignores NuGet.Config - c#

The NuGet.Config, .csproj and .nuspec are in the same folder (project folder). This is my NuGet.Config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="..\packages" />
</config>
</configuration>
When I type nuget pack in powershell in the project folder, the .nupkg file is created in the same folder, not in the ..\packages folder.
Versions:
NuGet Version: 4.1.0.2450, Visual Studio 2015
I've googled for hours and still no luck for a working solution.
Tried this one still not work: nuget.config is ignored, specifically the repositoryPath

Related

In an MS Build project file, can a Nuget package reference be given a path?

I have a Nuget package that is downloaded to a non-standard location in my project folder.
Is it possible to reference this package in an fsproj or csproj file?
Something like:
<ItemGroup>
<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0">
<HintPath>./external/packages/Contoso.Utility.UsefulStuff.3.6.0/</HintPath>
</PackageReference>
</ItemGroup>
Nuget can have multiple sources for packages, that can be configured with a nuget.config file. Source can be either URL of some site, like nuget.org or private feed from gitlab, or it can be path to local directory, like C:/Packages/.
You should create nuget.config file in a root of repository with following content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- Make sure everyone have same sources for more reliability -->
<clear />
<!-- Add default nuget source, since we removed it -->
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<!-- Add new source that will point to directory with *.nupkg files.
Parameter 'key' can have arbitrary text -->
<add key="localFiles" value="./external/packages/" />
</packageSources>
</configuration>

Change nuget packages folder and use another NuGet.Config in Visual Studio

I want to change nuget package folder but it doesn't work.
I tried very much tricks but not work.
I restart many times VS but not work.
My config:
Visual Studio Community 2019
Windows 10 1909 x64
I have a VS solution folder
MyProjectSln\
HelloWorld\
bin
nuget_packages
NuGet.Config
I want VS studio nuget package manager console use the "NuGet.Config" file and put all packages downloaded in "nuget_packages"
So nuget packages must be in D:\MyProjetSln\HelloWorld\nuget_packages.
Content example of D:\MyProjetSln\HelloWorld\NuGet.Config :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value=".\nuget_packages" />
<!-- I have also tried with repositoryPath but not work -->
</config>
</configuration>
The xml syntax is correct in my case (in my file).
Example, when i execute the command "install-package NUnit" from Package Manager Console, it put downloaded packages in D:\MyProjectSln\packages\ and I don't want that.
Thank you for helping !
Just as this document said, the new nuget.config file must be under the same level directory of the project folder rather than put the file inside the project folder.
In other words, it must be located in at least the solution directory or a higher-level directory.
Note: if you use this way, it will act on all the projects in the same level directory and all the projects in the sub directory.
So you should put the new nuget.config file on the D:\MyProjetSln.
Then modify its content as:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<config>
<add key="repositoryPath" value="HelloWorld\nuget_packages" />
</config>
</configuration>
Then, close VS and then reopen your project to enable that function.
In my side,
At the time of writing this message, what I want is not possible at the moment.
Maybe it will be a feature later.

Why is my repositoryPath ignored in Azure DevOps / TFS?

First of all, I have a NuGet.Config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value=".\ExternalReferences\Packages" />
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</config>
</configuration>
In the root of my dev branch. It's job is, that every project in my dev branch restores the packages into \dev\ExternalReferences\Packages, which works fine localy.
Im trying to introduce Azure Pipelines via TFS (VisualStudio Team Services/DevOps) for my CI-Build.
However, TFS is restoring the packages into the wrong folder \dev\packages (where \dev is D:\a\9\s\) instead of \dev\ExternalReferences\Packages.
Acquired lock for the installation of Newtonsoft.Json 12.0.3
Installing Newtonsoft.Json 12.0.3.
Adding package 'Microsoft.Extensions.Logging.Abstractions.2.2.0' to folder 'D:\a\9\s\packages'
This breaks the build later (Which expects the ExternalReferences\Packages):
PrepareForBuild:
Creating directory "bin\Release\".
Creating directory "obj\Release\".
ResolveAssemblyReferences:
Primary reference "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL".
##[warning]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\a\9\s\Conwell.WebServices.Google\Conwell.WebServices.Google.csproj]
Any Idea how to make NuGet to restore to the correct directory?
I just created a standard Pipeline for the project type Asp.NET
Why is my repositoryPath ignored in Azure DevOps / TFS?
Since the nuget restore task restoring the packages into the wrong folder \dev\packages, it seems the settings repositoryPath in the NuGet.Config is ignored.
To resolve this issue, you could try to specify the nuget.config when you set the nuget restore task to make sure you have use the NuGet.Config:
Then my nuget.config looks like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AzureDevOpsFeed" value="https://pkgs.dev.azure.com/xxxn/_packaging/xxx/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<config>
<add key="repositoryPath" value=".\ExternalReferences\Packages" />
</config>
</configuration>
Then, as test result, I could get the package in the folder ExternalReferences\Packages:
Hope this helps.
As a workaround I configured the directory directly:
Go to pipeline, and edit:
Go to NuGet restore, Advanced and Destination Directory:
I am still open to options, which would respect the NuGet.Config.

how to set relative path in nuget.config?

I currently have the following nuget.config file. With automatic package restore it will create a package folder that is one level up from my solution folder. For example if my solution folder is on my desktop, the package folder will be generated within a /lib folder on my desktop. I would like for it to generate the /lib folder within my solution folder. How do I change the relative path to accomplish this?
<configuration>
<solution>
<add key="disableSourceControlIntegration"
value="true" />
</solution>
<config>
<add key="repositoryPath"
value="../lib" />
</config>
</configuration>
For example,
Bad: \desktop\lib\
Good: \desktop\mysolution\lib\
I tried this:
<config>
<add key="repositoryPath"
value="/lib" />
</config>
..and the package restore directory becomes c:\lib which is unexpected behavior.
In addition, please make sure your NuGet.Config file is added under your solution directory after you use "lib" path in that path.
I discovered that if I remove
<config>
<add key="repositoryPath"
value="../lib" />
</config>
...from nuget.config
Or
if I complete delete nuget.config (and use all defaults)
That the default behavior will be to create and add packages to this folder:
\desktop\mysolution\packages\
and while that is not named 'lib' it hardly matters - my key issue was to get the packages in to the solution folder.

Change current web.config with custom Nuget package

I am new at creating custom nuget package. I used NuGet Package Explorer and added new Class Library dll to my local nuget repository. Now I can install it to my new projects.
But Sometimes I need install my custom package and change current project web.config file. Add new key or section. Is this possible?
You can modify the web.config through a web.config.transform file or by using an XML document transform (XDT).
For a .transform you create a web.config.transform file and put in the Content directory of your NuGet package. The web.config.transform file contains the same as a web.config file and it will be applied to the web.config file when you install the NuGet package.
XDTs are more powerful and can do more complicated modifications to the web.config file, such as inserting or removing existing elements. You create a web.config.install.xdt and optionally a web.config.uninstall.xdt file in the Content directory of the NuGet package. These transforms are then run when the NuGet package is installed or uninstalled. An example, taken from the NuGet documentation, is shown below.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<modules>
<add name="MyNuModule" type="Sample.MyNuModule" xdt:Transform="Insert" />
</modules>
</system.webServer>
</configuration>
The full XDT syntax is documented on the MDSN website

Categories