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.
Related
We are using Visual Studio 2019 and we have a solution that has a references to some NuGet packages either from nuget.org or from our private server we are managing the solution with packages.config management, the problem is there is one ASP.NET project in that solution that does not install any of the required packages(in our case it misses the NewtonSoft.json), and installs all the other ones correctly, even though we have packages restore enabled, and there are other ASP.Net projects in the solution that install the Newtonsoft package correctly, but each time you read the last version of the solution from zero (in the case you delete the local solution and re-read it) from the TFS, you need to install the Newtonsoft.json manually for that project specifically.
PS: it's a problem that can be solved in 5 min every time but I know something is wrong and I have been trying to understand what is it, I don't want to solve it localy, but I need a solution the resolve it on the TFS level, so please help me if you can or if you know any other questions here that can help, please guide me through (if I didn't see it already).
My NuGet.Config document:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="MxNuget" value="our server path" />
</packageSources>
<activePackageSource>
<add key="All"
value="(Aggregate source)" />
</activePackageSource>
<packageRestore>
<add key="enabled" value="true" />
<add key="automatic" value="true" />
</packageRestore>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
the error we are getting is the following:
The name 'Newtonsoft' does not exist in the current context.
The problem I was having was because the TFS was not restoring all the packages needed because when he sees the Folder 'Packages' in the solution he just check if the package is inside, and when he is done, the version that he found and the one on the local machine may be different and that was causing the problem, so I wanted to delete my packages folder on the TFS but I couldn't find it. For that I installed a package in my solution which adds .tfignore to the .nuget folder in the solution directory, and that last file tells the TFS to ignore the packages file on the server and restor them always.
Questions that were useful:
1 - Tfs Can't restore Nuget packages.
2- NuGet Packages are missing
3- External: Missing Nuget Packages on TFS Build Server
I resolved the problem by following the steps:
installed the package DisableSourceControlIntegration to the project that was missing the Newtonsoft.json NuGet.
Unified all the versions of NewtonSoft.json on the projects to which my ASP.Net project has a reference. (I think that was the main problem because I had them unified before but I updated the whole group with their config files).
In the visual studio, open Tools --> Nuget package manager --> package manager setting and make sure that the Packages.config is selected as the format of managing the NuGet packages.
deleted all the packages cash.
Re-compiled the solution.
Pushed to the TFS.
I'm using VSCode with the official C# extension to develop a .NET Core console app on Ubuntu. I'd like to use a private nuget package in this console app. Usually one would add a local feed for nuget packages like described here with nuget init c:\packages \\myserver\packages. I've tried to find some settings in the C# extension which would allow me to configure a local feed for nuget packages but did not find any. Is it possible to do the same with the VSCode + C# extension builtin support?
Alternatively, you can create a file named "NuGet.Config" in the directory where the solution is located and do its contents as follows;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="KetumMyGet" value="https://www.myget.org/F/ketum/api/v3/index.json" />
<add key="KetumMyBaget" value="http://localhost:5000/v3/index.json" />
<add key="TestSource" value="c:\packages" />
</packageSources>
</configuration>
See more here
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
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
I have a solution with 25 C# projects aprox.
For every compilation of the solution, I tweak some project configuration usings precompilers directives.
When I need to add a directive to a configuration. I have to go to every project and add that directive. When I add a new configuration it is the same an worse.
In a C++ project I would had a .h file that would be included in all projects, to have something like a global configuration file.
But, how can I do something like that using Visual Studio and C#?
A good way to do this would be to reference external config files from each projects configuration.
You can create just one config file with the information/directories that are frequently changing and reference it from each projects config files.
For example:
directives.confg:
<appSettings>
<add key="ThisDirectory" value="This\Directory\Path"/>
<add key="ThatDirectory" value="That\Directory\Path"/>
</appSettings>
And in your web/app config you would have:
<configuration>
<appSettings file="C:\PathToYourExternalConfigFile\directives.config">
<add key="OtherKeyNotInExternalConfig" value="SomeValue" />
</appSettings>
</configuration>
Now only the directives.config file will need to be updated and all other projects will automatically have the latest config changes.
If you build your project using msbuild then all you need to do is set an environment variable with the same name as your define.
#if OPTION_ONE
// option one code here
#else
// option one not set
#endif
Then from the developer command prompt you can build like so
set OPTION_ONE=true
msbuild YourSolution.sln
If that doesn't work you could add the following to your project file
<DefineConstants Condition="'%(OPTION_ONE)' != ''">OPTION_ONE</DefineConstants>
Edit:
Create a common c# file for definitions the just like you would in c++ with a header.
Create a user file (i.e. MyProject.csproj.user) to include the common cs file. The user file doesn't need to be included in the project. Visual studio will automatically use it if it exists:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
<Compile Include="$(SolutionDir)CommonFile.cs"/>
</Project>
Copy that file to each project directory, changing the file name to match the project.
Or you can just add the common file as a link by adding existing item and click the option arrow next to Add and select Add As Link