I'm trying to build a C# console application using Visual Studio Code but when I try to install packages the application uses wrong local folder with as a local source.
I have dotnet installed in my C program files, I think the program will be solved if I can use my dotnet folder as a local source but I don't know how to do it.
I tried these commands in terminal :
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.Tools
and I get this error:
MovieAPP>dotnet add package Microsoft.EntityFrameworkCore Writing C:\Users\Ahmed\AppData\Local\Temp\tmpB0AD.tmp info : Adding PackageReference for package 'Microsoft.EntityFrameworkCore' into project 'E:\courses\C-Sharp\MovieAPP\MovieAPP.csproj'. log : Restoring packages for E:\courses\C-Sharp\MovieAPP\MovieAPP.csproj...
Writing C:\Users\user\AppData\Local\Temp\tmpACF8.tmp
info : Adding PackageReference for package 'Microsoft.EntityFrameworkCore' into project 'E:\courses\C-Sharp\MovieAPP\MovieAPP.csproj'.
log : Restoring packages for E:\courses\C-Sharp\MovieAPP\MovieAPP.csproj...
error: The local source 'C:\Users\user\Downloads\Compressed\WebMatrixExtensionsGallery' doesn't exist.
Related
Trying to add System.Management.Automation package to my project in visual studio because I want to run powershell commands through my code, but am getting the error:
The project does not support adding package references through the add
package command. My dotnet --version is: 7.0.102
I inputted
dotnet add package System.Management.Automation --version 7.3.2
into the package manager console, and was expecting it to work as normal when adding a nuget package, however instead received the error
Error while adding package 'System.Management.Automation' to project
'C:\Users\userone\source\repos\blackjack21\blackjack21.csproj'. The
project does not support adding package references through the add
package command.
No idea what to do.
The sample NotepadAndCalculatorTest project built in VS Code using the terminal command dotnet build throws the following errors:
C:\Program Files\dotnet\sdk\5.0.401\Microsoft.Common.CurrentVersion.targets(820,5): error : The BaseOutputPath/OutputPath property is not set for project 'NotepadCalculatorTest.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='AnyCPU'. You may be seeing this message because you are trying to build a project without a solution file,
and have specified a non-default Configuration or Platform that doesn't exist for this project. [C:\Users\<username>\VSCode Projects\WinAppDriverTryout\Test\Samples\C#\NotepadAndCalculatorTest\NotepadCalculatorTest.csproj]
Or:
NotepadCalculatorTest.csproj(109,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props.
Could someone point me towards a possible way to get rid of the errors?
dotnet build carries out an implicit restore as part of the command.
This uses dotnet restore which does not support project references in packages.config & is exactly what this project is using.
dotnet restore only supports .csproj package references.
That's why, this project builds perfectly fine in Visual Studio but dotnet build throws errors.
You can migrate packages.config to package references by right-clicking on the file within Visual Stduio and clicking migrate, however that still won't fix your problem as dotnet cli works properly with .NET Framework only if the project was created using the dotnet new command.
I assume this project was created in Visual Studio since it has a Visual Studio solution file - .sln - and so commonly have a differently structured .csproj format.
This then usually breaks some CLI commands, even if you migrate the references in this case.
You have 2 workarounds.
1. Use nuget restore
The easiest option is to download the NuGet CLI executable from here, taken from the downloads page.
If you are not on Windows, use this guide by Microsoft.
Add it to your PATH or place it in the root folder of the project.
Run nuget restore, which is compatible with packages.config (run .\nuget restore if you're inside PowerShell to trust the command as PowerShell does not does not load commands from the current location by default for security).
Your should get output similar to this:
PS C:\Users\StackOverflow\NotepadAndCalculatorTest> .\nuget restore
MSBuild auto-detection: using msbuild version '16.9.0.16703' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin'.
Restoring NuGet package Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview.
Restoring NuGet package Selenium.Support.3.8.0.
Restoring NuGet package Selenium.WebDriver.3.8.0.
Restoring NuGet package Castle.Core.4.2.1.
Restoring NuGet package MSTest.TestFramework.1.2.0.
Restoring NuGet package Newtonsoft.Json.10.0.3.
Restoring NuGet package MSTest.TestAdapter.1.2.0.
Adding package 'MSTest.TestFramework.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.Support.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Castle.Core.4.2.1' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Selenium.Support.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Castle.Core.4.2.1' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestFramework.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
NuGet Config files used:
C:\Users\StackOverflow\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
C:\Users\StackOverflow\.nuget\packages\
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Installed:
7 package(s) to packages.config projects
Then run dotnet build.
It won't try to run dotnet restore as the packages have already been restored by NuGet already so you won't get any errors:
PS C:\Users\StackOverflow\NotepadAndCalculatorTest> dotnet build
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Nothing to do. None of the projects specified contain packages to restore.
NotepadCalculatorTest -> C:\Users\StackOverflow\NotepadAndCalculatorTest\bin\Debug\NotepadCalculatorTest.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.08
2. Port the project
The 2nd workaround is to create a new project using dotnet new & port the code over so that your .csproj file works with dotnet restore and subsequently, dotnet build.
I would recommend option 1 unless you don't want to restore via NuGet.
I have a .NET project with the following in its .csproj
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
When I run dotnet restore project-file.csproj I get the following:
Nothing to do. None of the projects specified contain packages to restore.
Why is this? I thought the dotnet cli could work with non Core projects too?
I have nuget packages that are referenced, so I expect the cli to go and download the nuget packages.
dotnet cli works properly with .NET Framework only if the project was created from dotnet new command. If you create project from Visual Studio the structure of .csroj files will be different and you usually cannot run cli commands towards them
Visual Studio only allows you to run nuget commands from nuget console (package manager console) within Visual Studio itself.
If you want to do nuget restore from command line:
Download nuget executable from https://www.nuget.org/downloads
(it is not a installer/package, but actual executable!)
Save it to a folder of your choice and add it to the PATH.
Then, as suggested above: nuget restore solutionname.sln (but this time you don't have to run Visual Studio!)
I am having c# .net core project. Project name is Master and it has dependencies of external NuGet package as "SpecFlow.CustomPlugin". Master project has Two classes as Shape.cs and Factory.cs.
When I generate the NuGet package of Master project so that the implementation of Shape.cs and Factory.cs class can be useful as library into other projects. After generating the NuGet package of Master project I only see the "SpecFlow.CustomPlugin" content with it's own dependent dll files but I am not able to see dll of Master project in newly generated NuGet package.
Newly generated NuGet package is included in another project let's say Consumer. Consumer want to use the Shape.cs method and Factory.cs method but it's not accessible.
Master project Dependencies looks like:
First, make sure that Shape and Factory are public. If you don't specify their visibility, they're private by default, which means that they can not be used directly by other projects, either as package reference or project references.
When you pack master into a NuGet package, the default file it will create is bin\Debug\master.1.0.0.nupkg. Assuming master is targetting .NET Standard 2.0, master's dll is saved as lib\netstandard20\master.dll in the nupkg. You need add/push this nupkg to a nuget feed (can be a directory on your computer or network, nuget.org or you can host your own feed). Your comsumer project will need a nuget.config that adds the correct NuGet feed as a source, then you add a package reference to the master package. After you restore (which Visual Studio does automatically if you added the package with the UI), then you can use any of master's public classes.
Here's commands you can run on the command line to set up two projects, one is a package, the other will consume it. If you're using .NET Core in Visual Studio, it must have already downloaded the .NET Core SDK, which puts the dotnet cli on your path. You'll also need to download nuget.exe from https://www.nuget.org/downloads/.
dotnet new nugetconfig
nuget source -configfile nuget.config add -name local -source feed
# create an isolated nuget environment, because I don't like to populate
# my global packages folder with test packages
nuget config -configfile nuget.config -set globalPackagesFolder=gpf
# create a library, pack it, and add the nupkg to our local feed
dotnet new classlib -n MyLib
dotnet pack MyLib\MyLib.csproj -o nupkgs\
nuget add MyLib\bin\Debug\MyLib.1.0.0.nupkg -s local
# create console app and reference MyLib
dotnet new console -n MyApp
dotnet add MyApp\MyApp.csproj package MyLib --version 1.0.0
#if you want to open these projects in Visual Studio
dotnet new sln -n sample
dotnet sln add MyLib\MyLib.csproj
dotnet sln add MyApp\MyApp.csproj
start sample.sln
Normally you wouldn't use a NuGet package to use one project from another project in the same solution. Just make them project references, and when you pack a project into a NuGet package, the project reference becomes a NuGet dependency. I only did it this way to demonstrate how to easily consume a package that you created yourself.
Here are the steps that I follow to create and publish a class library to a private nuget server:
Create a class library project using VS2017.
Install log4net package from nuget.org using the nuget package manager.
Open cmd.exe, locate the project folder, execute:
nuget pack.
Verify that the mylibrary.version.nupkg file is created in the project folder.
On the terminal window, execute:
nuget push mylibrary.version.nupkg -source http://private.nuget.server
No problem till here. Now let's consume the package from another project:
Create another VS2017 project.
Open cmd.exe, locate the project folder, execute:
nuget install mylibrary -source http://private.nuget.server -source https://api.nuget.org/v3/index.json
At this poing I get the error below:
Attempting to resolve dependency 'log4net (≥ 2.0.8)'.
Unable to resolve dependency 'log4net (≥ 2.0.8)'.
It seems that the installation of an external package reference relative to the private nuget server fails. Nuget.exe looks for the dependent package (log4net, for this example) at the private nuget server, not at nuget.org.
I tried many options (including creating and using a special nuget.config file) but can't find a way through. Any thoughts?