how to set relative path in nuget.config? - c#

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.

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.

VS2015 NuGet private package repo source not updating

I have an issue in VS2015 where adding a NuGet source is not working.
The picture below shows the source. The URL and package name is correct and working (I can successfully push packages to the repo).
The problem is when I add it, check the checkbox, and select "Update" and "Save", it does not activate the source. When I go back into the dialog, the checkbox is unchecked. It remains unchecked no matter what I do.
I think this is a GUI issue, the problem seems to be it simply is not enabling it. Is there a config option in a project file I can manually this package source?
(Note that "NAME" and "http://myrepo.com" are not the real source name and url, but I have verified they are correct by pushing to it successfully.
Edit:
I checked the NuGet.config file and there is indeed an entry in the file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="NAME" value="http://myrepo.com" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
I had been running VS as administrator due to using a local IIS instance which requires administrator privileges, magicandre1981 pointed out that NuGet.config needs write permissions, so I gave full access to the folder to normal users (I believe the NuGet.config file was generated under the administrator context therefore lacking normal user permissions).
This by itself did not solve the issue, but doing a Nuget Package Restoreafterwards, caused the NuGet feed to display again.

Is there a connection between nuget.config and gui settings?

When trying to generate a build, I am getting the following error:
1 error(s), 0 warning(s)
$/source control my solution....../Web.sln - 1 error(s), 0 warning(s), View Log File
D:\Builds\.....zWeb\.nuget\NuGet.targets (93): The underlying connection was closed: An unexpected error occurred on a send.
I am configuring the repository URLs both here:
And in the NuGet.config file:
I've tried the following:
tried multiple network connections (to rule out firewall issues)
restarted VS and reinstalled NuGet and all packages
cleaned, rebuilt
changed the downloadnuget setting
What am I doing wrong? How do I get this to build?
In case it is relevant, here's my nuget.targets file.
Hi try to place file nuget.config
in root of your solution like
x:\SolutionFolder\nuget.config
x:\SolutionFolder\Web.sln
then change nuget.config
to have
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="packages" />
</config>
<packageSources>
<add key="Your NuGet" value="\\YourServer\Nuget Gallery" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
</configuration>
the repositoryPath is relative to nuget.config file localization
create this network share and be sure that your use have access to it
<add key="Your NuGet" value="\\YourServer\Nuget Gallery" />
What tfs version and visual studio version you use localy and on the build server ?

how to access an XML file stored in the same directory as the DLL when DLL is installed in GAC

I have a dll project which have an xml file. [content of that dll project]
I have installed that dll in My GAC. In some method of that dll I needed to load that xml file. but I can't able to find the path or way by which I can load that xml,
My xml files looks like following
<Data>
<add key="Hostname" value="192.XXX.XXX.111" />
<add key="UserName" value="root123" />
<add key="Password" value="admin1234" />
<add key="SFTP_IncomingFileFolder" value="/root/Inbox/" />
<add key="SFTP_ArchivedFileFolder" value="/root/Archived/" />
<add key="SFTP_OutGoingFileFolder" value="/root/Outbox/" />
<add key="Local_IncomingFileFolder" value="D:\phpFiles2\Inbox\" />
<add key="Local_OutgoingFileFolder" value="D:\phpFiles2\Outbox\" />
<add key="Local_OutgoingArchive" value="D:\phpFiles2\Archived\" />
<add key="ApplicationFolderPath" value="D:\SFTP_Installation\" /><!-- where WinSCP.exe resides-->
</Data>
Expanding from the comments:
You cannot. When you install a DLL in the GAC, only that DLL gets copied into the GAC. You cannot avoid this, at least not in any supported way.
You mentioned in the comments that you want to let your DLL read configuration options. Some workable alternatives for that:
Store the settings in the registry.
Store the settings in the user profile directory.
Store the settings in C:\ProgramData.
Let the calling program (your PHP script) control the settings, and let that calling program read the settings from a file in the program's directory.
None of those options require any files in the same directory as your DLL.

Categories