I don't want to rely on nuget service for downloading dependency. I want to download and use nuget packages locally in my .Net Core app. Is it possible?
Approach is the same as was before: open your NuGet.config file and add your local feed (path to local folder with pacakages. See Hosting your own Nuget feed doc):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
...
<add key="LocalFeed" value="<path to your local folder>" />
</packageSources>
You can modify default NuGet.config file
The default location for NuGet's configuration file is %APPDATA%\NuGet\NuGet.Config (DOS) or $ENV:APPDATA\NuGet\NuGet.Config (PowerShell).
or create your own file in root folder of your solution.
Related
I am using VS code and not Visual Studio to run my .NET core 3.1 web app.
I have a .NET core 3.1 app. As I am using an Client VDI machine ( It is using Win 7 SP1 operating system) which is blocking the Nuget.Org URL currently.
so as a work around, I have copied over all the Nuget package into an folder in my VDI and updated the path in the Nuget.Config.
But still I am getting below
Missing Package" error. My App do not DIRECTLY depends on these packages.
following is my Nuget.Config file,
<?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="nuget.org" value="C:\NugetPackageDownloadLocation" / >
</packageSources>
</configuration>
any help will be appriciated.
Have you tried adding a package source via the CLI? Given how .NET Core handles transitive dependencies getting all the packages required for a relatively complex solution might be tricky.
nuget sources Add -Name "MyServer" -Source \\myserver\packages
Through automatic nuget restore is convenient it is not safe. I previously checked in all packages into the repository. This was easy as VS created a packages directory under the project root.
Now I find I have a
~/.nuget
directory outside the project hierarchy. Is there a way to revert the behavior? Perhaps a flag in the *.csproj file?
You can change the location for the global package folder to a solution-local location by specifying a path in a NuGet.Config file next to the solution (note that you have to re-open the solution for this to have an effect):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value=".\packages" />
</config>
</configuration>
There are two properties that can be set this way to affect the location of where the packages will be restored to. repositoryPath for packages.config projects and globalPackagesFolder for project.json and projects usingPackageReference.
I have got a project with two web apps. One of them is only for reference in the base app. The project runs okay in visual studio. I am trying to publish it in local file system and then copy it across to the windows server 2008. Below is the web.config generated by visual studio.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="bootstrapper-version" value="1.0.0-beta4" />
<add key="runtime-path" value="..\approot\packages" />
<add key="dnx-version" value="1.0.0-beta4" />
<add key="dnx-clr" value="clr" />
<add key="dnx-app-base" value="..\approot\src\MySite" />
</appSettings>
</configuration>
When I run this website in Server using dnx . web, it runs okay. But when I try to run it under IIS by pointing IIS to wwwroot then all of the packages go missing. The website is unable to find packages.
Failed to resolve the following dependencies for target framework 'DNX,Version=v4.5.1':
Base32 1.0.0.13
BouncyCastle 1.7.0
CsQuery 1.3.4
EcmaScript.Net 1.0.1.0
EntityFramework 7.0.0-beta4
EntityFramework.Commands 7.0.0-beta4
EntityFramework.Core 7.0.0-beta4
EntityFramework.Relational 7.0.0-beta4
EntityFramework.Relational.Design 7.0.0-beta4
EntityFramework.SqlServer 7.0.0-beta4
EntityFramework.SqlServer.Design 7.0.0-beta4
.........
.........
How did you deploy?
Here are the steps that you can follow to get that running:
Make sure that you the app pool is a .NET 4 app pool
Run, in your web app's project folder dnu publish --runtime <name of runtime> (the name is the name of the runtime folder under %userprofile%\.dnx\runtimes
Step 2 generates a folder that contains the application, its dependencies and the runtime under the bin\debug folder.
Copy that folder to the IIS website folder
Run
I copied the HelloMvc project folder to another folder "Ricky" and ran kpm restore, I got the following output:
I have no idea what's wrong. the "kpm restore" ran successfully in its original folder which is cloned from the asp.net/home repository.
Finally I figured out the solution. Thanks for the open source of ASP.NET vNext, I found out the source code of "restore" command.
During the restore process, the restore command tries to find out the "root" folder of the project by this method:
public static string ResolveRootDirectory(string projectDir)
{
var di = new DirectoryInfo(projectDir);
while (di.Parent != null)
{
if (di.EnumerateFiles("*.global.json").Any() ||
di.EnumerateFiles("*.sln").Any() ||
di.EnumerateDirectories("packages").Any() ||
di.EnumerateDirectories(".git").Any())
{
return di.FullName;
}
di = di.Parent;
}
return Path.GetDirectoryName(projectDir);
}
because the HelloMvc folder doesn't have those files or packages folder, so the parent folder of HelloMvc will be the root folder.
The root folder is significant because we need to copy "NuGet.config" file to the root folder. The NuGet.config indicates the package source of "AspNetVNext", so assemblies of asp.net vNext can be found.
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/" />
<add key="NuGet.org" value="https://nuget.org/api/v2/" />
</packageSources>
<packageSourceCredentials>
<AspNetVNext>
<add key="Username" value="aspnetreadonly" />
<add key="ClearTextPassword" value="4d8a2d9c-7b80-4162-9978-47e918c9658c" />
</AspNetVNext>
</packageSourceCredentials>
</configuration>
for myself, I created a packages folder in my HelloMvc folder and copied the NuGet.config to HelloMvc folder. So the HelloMvc folder itself is the root folder and NuGet.config is in position, the kpm restore succeeded.
It is possible that those specific versions of the packages are no longer available on the CI server.
Open project.json with a text editor and replace specific versions with * versions.
For example:
"Microsoft.AspNet.Diagnostics": "0.1-alpha-build-0623",
"Microsoft.AspNet.Hosting": "0.1-alpha-build-0519",
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-build-0469"
becomes
"Microsoft.AspNet.Diagnostics": "0.1-alpha-*",
"Microsoft.AspNet.Hosting": "0.1-alpha-*",
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-*",
* version means "pick the latest version of that package".
The easiest solution would be;
Add/Create the NuGet.config file within main application directory, the content of the NuGet.config is;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetmaster/api/v2" />
<add key="NuGet.org" value="https://nuget.org/api/v2/" />
</packageSources>
</configuration>
Then make sure your application folder is one level down from the nuget.config file, the folder structure is;
[Main_Folder]
Nuget.config
[Application_Folder]
Then it should work!
I added Fody ProperyChanged to two projects in my solution. Package Restore is enabled on the solution. However, the TFS Build Service fails building with the following error:
WindowsUI.csproj (443): The imported project
"SolutionDir\Tools\Fody\Fody.targets" was not found. Confirm that the
path in the declaration is correct, and that the file exists
on disk.
The folder is indeed not there. I could check it into source control, obviously. However, should it not be populated by the NuGet Package Restore? Or am I misunderstanding what NuGet Package Restore does?
I ran into a similar problem trying to get a solution to build on Visual Studio Online.
Problem is that packages are restored before a project build, but before that the project
files and target inclusions from packages (still to be restored) have already been interpreted.
Use the before build hook as described here:
http://sedodream.com/2010/10/22/MSBuildExtendingTheSolutionBuild.aspx
In your before.solutionname.sln.targets file put something like this to force all packages to be restored before even the first project is built:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="BeforeBuild" BeforeTargets="Build">
<Message Text="Restoring all nuget packages before build" Importance="high">
</Message>
<Exec Command=".\.nuget\NuGet.exe restore YourSolution.sln" />
</Target>
</Project>
If you have external package sources configure them in your nuget.config file which should
also be in the .nuget folder. For example:
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<add key="YourSource" value="http://yoursource.somewhere.net/nuget" />
</packageSources>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
</configuration>
As of version 1.13.0.0 (released March 23, 2013) Fody is a 100% nuget deployed tool and as such it will work with package restore.
https://nuget.org/packages/Fody/
This will appear when you install the Fody Nuget
https://github.com/Fody/Fody/blob/master/NuGet/readme.txt
UPDATE: This answer now only applies to versions prior to 1.13.0.0.
The files in SolutionDir\Tools\Fody cannot be deployed through nuget and needs to be checked into source control
You are running into the same issue that I did when I tried to ship a build update in NuGet package. The issue is that NuGet package restore is invoked during the build process. Because of this if NuGet package restore restores a .targets file that is imported, it is restored too late. By the time the file is written to disk the <Import element has already been evaluated and skipped due to the file not being on disk.
The best thing that I have found is to build another project to invoke the package restore for you. In order to smooth this out for my own SlowCheetah NuGet package when the NuGet package is installed I create a packageRestore.proj file in the same director as the .csproj/.vbproj. Then users can build this project file and then the .sln/.csproj/.vbproj. By doing this the NuGet packages are restored and then the build process is kicked off.
If you are interested in using my packageRestore.proj I can re-factor that part of SlowCheetah NuGet package into its own and your NuGet package can depend on that one. Let me know if you are interested in that.