How to get the nuget cache folder location - .net-core

I am writing a dotnet core tool and need to find a sibling nuget package from my tool. If i was on full .net framework i could have found it with
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),".nuget...");
Anyone have a sugestion to find the package folder when not having the Environment stuff avaible? (If nothing exists, i can live with it not working on unix)
the dotnet core tools can be used in project.json tools section.

In Nuget 3-3.5 you may use the following to get cache folder location
nuget locals packages-cache -list
After Nuget 3.5 this is currently not supported, but accordingly to this opened issue, Nuget team will consider those feature in future.

Related

Pipeline Nuget restore failing on .Net Core 3.0 Preview 8 project (NU1202)

I updated a project from netcoreapp2.2 to netcoreapp3.0 and use Preview8 SDK as well as Microsoft.EntityFrameworkCore.SqlServer, tools, and design.
I can build and run my projects locally just find (VS 2019). But when I try to deploy with Azure DevOps, the Nuget restore gives this error:
NU1202: Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0-preview8.19405.11 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0-preview8.19405.11 supports: netstandard2.1 (.NETStandard,Version=v2.1)
Every reference to an EntityFrameworkCore package will result in that error.
I'm setting the .Net Core SDK in the pipeline to Preview8 via a global.json.
I have a NuGet tool installer task, bringing in the latest version, and a Nuget Restore task command running against my solution.
My problem was that I was using the Nuget Restore. Changing it to dotnet restore made the trick.
This problem is caused by an obsolete version of NuGet agent.
Use NuGet Install Tool task (a.k.a. Use NuGet) and setup the agent to the v5.x.
This is a low profile solution.
EDIT: Yay, I have enough rep to comment now.
It turns out the easier fix is to updatethe NuGet package version to the latest (5.3.0) in the "Use NuGet" task.
Not enough rep to comment on Fernando's response but it worked for me.
Edit the pipeline's Agent tasks:
add .NET Core, Display name: dotnet restore, Command: restore
set up other properties pretty much the same as the existing NuGet Restore
remove NuGet restore
Pipeline Nuget restore failing on .Net Core 3.0 Preview 8 project (NU1202)
If you are using the host agent, you should make sure you have install the netcoreapp3.0 on the agent. You could use the task Use .NET Core to install it:
Note check the option Include Preview Versions.
Note: Since netcoreapp3.0 supported by Visual Studio 2019, so, you need to make sure your agent is Hosted Windows 2019 with VS2019.
Hope this helps.

Migrate to PackageReference Missing Nuget Build Failure

I have a Xamarin Forms Project - the Android project targets API 28 (Pie) and uses packages.config for the nuget references. All of the packages have a targetFramework="monoandroid90". The project compiles and runs correctly.
I want to migrate to using PackageReference, so I use the Migrate packages.config to PackageReference option.
After this completes I try to build the project and receive an error regarding a missing package:
Xamarin.Android.Support.Annotations.28.0.0.1
Looking in the packages folder, I can see that none of the Xamarin.Android.Support packages have been downloaded and I can't get them to download - even by reinstalling the package.
I also noticed that the csproj file reference monoandroid81 for all the nugets, even though the packages.config used monoandroid90
Has anyone had a similar difficulty after migrating?

Visual studio 2017 Update 3 - The SDK 'Microsoft.NET.Sdk.Web' specified could not be found

Error:
C:\WebApp\WebApp.csproj : error : The SDK 'Microsoft.NET.Sdk.Web' specified could not be found. C:\WebApp\WebApp.csproj
I am trying to open Dotnet core project and I am getting the above error.
I have installed the latest SDK from https://www.microsoft.com/net/core#windowscmd
I have checked the path for dotnet cmd and it works fine.
Am I missing something? Let me know if you need more information.
The target framework is set to .NET 4.5.2
I stumbled upon this issue a number of times recently. Here's a brief list of the workaround I found (one of them always worked until now):
Install the right .NET Core SDK: Either the latest version or the version required by your project.
Clean-up obsolete .NET Core versions: Go to Control Panel and uninstall previous .NET Core SDK/Runtime versions (as long as you don't use them anymore).
Create a Global.json file: Add a new global.json file to your project's root with the following content (replace the .NET Core version build with the one you want to run the project with):
{
"sdk": {
"version": "2.0.5"
}
}
Rename the SDK reference: Open your .proj file and replace <project sdk="Microsoft.NET.Sdk.web"> with <project sdk="Microsoft.NET.Sdk"> .
Add the MSBuildSDKsPath Environment Variable: The dotnet CLI sets the MSBuildSDKsPath environment variable when invoking MSBuild: however, a December 2016 patch changed the CLI behaviour so that it will respect an existing environment variable, if it has already been set: this will allow the developer to “force” the CLI to use a specific SDK.
Check your PATH: Verify that both C:\Program Files\dotnet and C:\Program Files (x86)\dotnet are in the PATH environment variable.
For additional info regarding the issue and other viable fixes check out this blog post that I wrote on this topic.
I agree with the comment on Sundeep's answer, you shouldn't have a global.json file in your project anymore.
It seems as though installing the .NET Core 2.0 SDK is causing issues with the PATH. Verify that C:\Program Files\dotnet and C:\Program Files (x86)\dotnet are in the PATH environment variable. In my case, these values were already present under System Variables so I added them to User Variables and rebooted my machine. This resolved my issue.
As suggested in the comment, I updated global.json file as shown below
{
"sdk": {
"version": "1.0.0"
}
}
Also, I had to remove the <ItemGroup> which contains wwwroot files path in .csproj file.
Reload the project and it works like a charm!
I've encountered the same problem, I just rename <project sdk="Microsoft.NET.Sdk.web"> to <project sdk="Microsoft.NET.Sdk"> on csproj
another situation:
https://stackoverflow.com/a/55529011/2971851
issue details: 2.1.6xx & 2.2.2xx version of the SDKs are only supported
on Visual Studio 2019. VS 2017 needs 2.1.5xx & 2.2.1xx versions of the
SDK.
How to fix the issue? Install 2.1.5xx version of the SDK if you are
targetting a 2.1 app Install 2.2.1xx version of the SDK if you are
targetting a 2.2 app.
and according to the official document:
Note: If you are a Visual Studio user, there are MSBuild version
requirements so use only the .NET Core SDK supported for each Visual
Studio version. If you use other development environments, we
recommend using the latest SDK release.
Do not uninstall previous SDK versions!
When I followed the 2nd step suggested in Darkseal's answer, uninstalling the previous SDK versions, it caused an "expected imports are missing" fatal error every time I opened up my project, so I needed to repair my Visual Studio, since installing the old SDK versions again kept popping up this error...
Also the other steps mentioned in that answer did not make any difference (both dotnet references were present in the environment variables and MSBuildSDKsPath was not needed for me).
Install the proper SDK version and select it in the Solution's Properties
As Jyoten mentioned I was using VS2017 x86 version and my SDKs were x64.
However, this was not the only issue, it seems there's some incompatibility with some SDK versions and VS2017. Having installed SDK v2.2.203 and v2.2.202, they would never showed up in the Target framework dropdown when I double-clicked the Properties on my project's solution (in the Solution Explorer (Ctrl+Alt+L)).
So I needed to install v2.2.105 x86 as mentioned in this answer, for it to show up in that dropdown.
Once it did, the solution that was requiring .NET Core v2.2 worked properly (did the Build normally).
I had this issue when I had to open a .Net Core 1.0.4 project in VS2017.
When I installed 1.0.4 SDK, i chose the x64 version which placed the sdk files in 'c:\Program Files\dotnet' ...
but my VS2017 was 32bit and was therefore looking for the sdk in 'c:\Program Files (x86)\dotnet'.
Once I installed the 32 bit version of the SDK it worked fine.
I was running into an issue where creating a new ASP.NET Core 2.0 project was giving me an error The SDK 'Microsoft.Net.Sdk.Web' specified could not be found, and leaving me unable to open the project in Visual Studio. The problem was the project was created in a folder that contained a global.json file, tying the SDK version to 1.0.0.
Deleting the global.json, or updating it to 2.0.0, fixed the issue. Be sure to check parent folders too - if any parent folder contains a global.json, the SDK version specified in the "closest" folder will be used.
I was getting this error in Visual Studio Code.
I was able to find the issue by setting the OmniSharp log settings in VS Code to debug. Once I did that I could see that it wasn't finding Microsoft.Build.Resources.dll.
I installed MS Build by repairing my VS 2017 Community installation. That fixed it.
uninstall and reinstall microsoft .NET core SDK.
then restart visual studio.
this works for me.
Choose the proper SDK according to your Visual Studio and Operating System. I downloaded the correct version from here https://dotnet.microsoft.com/download/visual-studio-sdks and after that .Net Core appeared in target frameworks list (there is a strict dependence between sdk version and VS version, so be careful).
I have solved this issue by,
go to this site, https://dotnet.microsoft.com/download
In that, install both .NET Core Runtime and .NET Core SDK.
After you install that, Open the Visual Studio 2017 with an administrator, Now The problem has been gone😊
I edited the .csproj file and changed netcoreapp2.2 to netcoreapp2.1 in this stanza & then I was able to get it working.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
Install the proper SDK version and go to below links
https://dotnet.microsoft.com/download/dotnet-core/thank-you/sdk-3.1.403-windows-x64-installer
https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-desktop-3.1.9-windows-x64-installer
This worked for me:
Make sure that the .NET folder where SDKs are and Visual Studio are
in the same program files (x86) or program files.
Provide the path to the SDK in the environment variable.
If anyone else stumbles upon this issue (including future me), I had the same problem and tried literary every solution proposed here and nothing worked. Finally what fixed the issue for me was deleting NuGetFallbackFolder in C:\Program Files\dotnet\sdk.
After deleting that folder, everything just started to work magically.
I had this error when from old project (in .NET 4.7.2) I was trying to do:
var project = new Microsoft.Build.Evaluation.Project(someDotNet6ProjectPath);
The solution was to upgrade Microsoft.Build packages.

Where to download previous version of .net core sdk?

We have a project that uses .net core sdk 1.0.0-preview2-003121.
Currently, I'm setting up a CI server to do automatic builds. In the server, I'm getting this error because the .net core sdk that is installed is not the same as the one in the project.
ERROR
preview2-003121 which is not installed or cannot be found under the path C:\Program Files\dotnet.
I did a command line check dotnet --version and it gave me 1.0.0-preview2-003131
Where can I download older versions of the .net core sdk? I have tried the following links and they give me the latest version for the download
https://github.com/dotnet/cli
https://www.microsoft.com/net/core#windows
This article explains how to install the correct .net core version. HTH.
http://blog.stephencleary.com/2016/06/dotnet-netcore-versions.html
I was able to just get away with following
download https://dotnetcli.blob.core.windows.net/dotnet/preview/Binaries/1.0.0-preview2-003121/dotnet-dev-win-x64.1.0.0-preview2-003121.zip
copy 1.0.0-preview2-003121 directory inside dotnet-dev-win-x64.1.0.0-preview2-003121.zip\sdk
paste in C:\Program Files\dotnet\sdk
Note: I had newer sdk version already installed(1.0.0-preview2-1-003177)
---Update---
Official download location is https://github.com/dotnet/core/blob/master/release-notes/download-archive.md as mentioned by vinicius-paiva and manoj-attal.
If you are looking to download specific version of .Net core, you can download from here. It worked for me.
Dot Net Core Download Archive List
Install using the chocolatey packages, of course.
Even though it is a late answer, it might help others.
Check these out.
https://github.com/dotnet/core/blob/main/release-notes/download-archive.md
https://www.microsoft.com/net/download/all

ASP.NET Core 1 RC2 add reference to "Microsoft.Data.SqlXml"

I created a MVC 6 project with RC1 and added reference to "Microsoft.Data.SqlXml" with no problem. When I migrated to RC2, I can not add the reference to "Microsoft.Data.SqlXml". I get an error message ".Net Core projects only support referencing .NET framework assemblies in this release. To reference other assemblies, they need to be included in a NuGet package and reference that package." Is there a easy way I can add the reference?
I'm finally able to add the reference "Microsoft.Data.SqlXml" by creating NuGet package, to the project migrated to RC2.
Publish RC1 project to file system and find out the package folder "Microsoft.Data.SqlXml" under "PublishOutput"
Download Nuget Package Explorer and open the .nuspec file in "Microsoft.Data.SqlXml" package folder.
Edit the files .nuspec, project.json, project.lock.json in Nuget Package Explorer, change all words "DNX" -> ".NETFramework", and "Save As" package file Microsoft.Data.SqlXml.nupkg.
In VS 2015, Tools -> NuGet Package Manager -> Setting, add local folder to package source list, then copy the .nupkg file to the folder
Install the Microsoft.Data.SqlXml NuGet package from the local source
I don't know why MS made the thing so complicated, 2 seconds work in RC1 but took me one day to figure it out in RC2.

Resources