I'm in the thick of trying to get up-to-speed on asp.net core / npm / react using this as a base project template:
https://github.com/jonmcquade/aspnetcore-react-redux#local-no-docker
I originally ran into troubles once trying this command:
dotnet build -c Release -o ./app
The error I was seeing:
A compatible SDK version for global.json version: [2.1.0] from
[global.json] was not found Did you mean to run dotnet SDK commands?
Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
I had the specific versions in the documentation installed and I have installed the latest versions, both x64 and x86 platforms.
I now also get this error running the npm install command or the dotnet --version command, yet I have SDKs installed.
It feels like the machine configuration has become broken somehow. I seem to have gotten into a bit of a version pickle trying to get the dotnet build command working and now even NPM isn't working.
Global.json is:
{
"sdk": { "version": "2.1.0" }
}
And the .csproj file contains:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.0-preview1-26216-03</RuntimeFrameworkVersion>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable>
<AssemblyName>FlightSearch</AssemblyName>
<RootNamespace>FlightSearch</RootNamespace>
<ApplicationIcon>ClientApp\favicon.ico</ApplicationIcon>
<Authors>Jon McQuade</Authors>
<Company>ACME Freelancing, Inc.</Company>
<StartupObject></StartupObject>
<Product>Flight Search</Product>
<Description>ASP .NET Core 2.1 MVC SPA with React and Redux</Description>
<RepositoryUrl>http://github.com/jonmcquade/aspnetcore-react-redux</RepositoryUrl>
<PreserveCompilationContext>true</PreserveCompilationContext>
<TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
<OutputType>Exe</OutputType>
<Version>2.1</Version>
</PropertyGroup>
What am I missing to get this working?
Are there some machine configuration issues that I can check? Maybe environment variables? I've tried running a repair using the installers but this doesn't address the issue.
The global.json specifies the SDK version of .NET Core that is being used to build your application. This has little to do with the .NET Core Runtime version that you want to run your application with.
Your application is a netcoreapp2.1, so you are running the .NET Core 2.1 Runtime. The earliest SDK Version for that is 2.1.300.
Since that is the latest .NET Core version, you actually don’t need to use a global.json at all: Just delete the file from your project and the tooling should use the latest version which is 2.1.300-rc1 on your machine.
If you're running into this issue on OSX you can fix the issue thusly:
which dotnet
ls + the output from the previous command
You should now see something like:
/usr/local/share/dotnet/dotnet
The directory that has your dotnet binary should also have a directory called sdk, so for the above example you can run ls /usr/local/share/dotnet/sdk, which should output a directory with your current version number. In my case that is 2.1.403 (there may be a better way to get the version number, but I was unable to run dotnet --version without specifying the correct sdk)
If I now open the global.json file in my app's root directory and change the sdk version to "2.1.403-osx-gs-x64", I should now be able to run dotnet command such as dotnet run from within my project.
Just make sure the required SDK version is installed in your machine. On your error, it's .NET core 2.1.0. You don't need the global.json file anymore.
Related
While trying to use HeaderNames.XFrameOptions, I found that it works in one of my projects and fails in another. Both are targeting .NET 6.
In my app, I need to work with the X-Frame-Options HTTP header. When possible, for maintainability reasons, I try to evade specifying constants for such standard strings myself, relying on standard constants instead. For this header's name, there is HeaderNames.XFrameOptions, available since ASP.NET Core 3.0.
By navigating to the class's implementation in VS, I found that the project where it works uses version 6.0.0.0 (.NET 6, x64) of the Microsoft.Net.Http.Headers assembly:
C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\6.0.12\Microsoft.Net.Http.Headers.dll
The project where it does not work uses version 2.2.0.0 (.NET Standard 2.0, MSIL) of the assembly:
C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.net.http.headers\2.2.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll
The working project is the main project of my console app and the broken project is a library in the same solution, directly referenced by the console app.
When I looked into the broken project's obj\project.assets.json, I found that Microsoft.Net.Http.Headers is really used in version 2.2.0 and it is referenced by Microsoft.AspNetCore.Http.Extensions/2.2.0, which is also used in the broken project.
I used that info to reproduce the failure:
dotnet new globaljson --sdk-version 6.0.404 --roll-forward disable
dotnet new console -f net6.0
dotnet add package Microsoft.AspNetCore.Http.Extensions --version 2.2.0
echo "Console.WriteLine(Microsoft.Net.Http.Headers.HeaderNames.XFrameOptions);" > Program.cs
dotnet run
C:\Repos\playground\Program.cs(1,58): error CS0117: 'HeaderNames' does not contain a definition for 'XFrameOptions' [C:\Repos\playground\playground.csproj]
The build failed. Fix the build errors and run again.
I tried adding all the packages referenced by the working project to the repro project and it fixed it! By elimination and following the dependencies of the last remaining project, I found that the fix can be achieved by adding just a single package (AspNetCore.HealthChecks.UI.Client/6.0.5):
dotnet add package AspNetCore.HealthChecks.UI.Client --version 6.0.5
dotnet run
X-Frame-Options
I see that AspNetCore.HealthChecks.UI.Client references the Microsoft.Net.Http.Headers assembly version 6.0.0.0, but directly, as an assembly, not as a NuGet package. Sadly, the latest packaged version is 2.2.0.0.
How can I make HeaderNames.XFrameOptions work in both my projects at the same time? Is installing an irrelevant package like AspNetCore.HealthChecks.UI.Client the only solution? And is there a more straightforward way to diagnose such assembly resolution issues?
I am trying to build Microsoft.AspnetCore.Identity from sources. The instructions are here: https://github.com/dotnet/aspnetcore/blob/master/docs/BuildFromSource.md. I am trying to run their command "restore.cmd" and hitting the following error:
error : Version 3.1.10 2 of the .NET Core SDK requires at least version 16.3.0 of MSBuild. The current available version of MSBuild is 16.0.46
1.62831. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
The error message's suggestion of changing the .Net Core SDK version seems absurd. Surely the solution is to install MSBuild 16.3.0. But how do I do that?
As an aside which may or may not be relevant, the instructions also have a script for installing the "exact required" version of VS. But it seems to install a new one that goes side-by-side with my existing version. Their "startvs" command then starts the existing one, rather than the new one. It has to be better to add everything needed to the existing installation. But I'm missing how to add MSBuild 16.3.0.
The error message's suggestion of changing the .Net Core SDK version
seems absurd. Surely the solution is to install MSBuild 16.3.0. But
how do I do that?
1) Please make sure that you have run ./eng/scripts/InstallVisualStudio.ps1 to install the required tools.
2) If you have VS2019, try to enable the option Use previews of the .NET Core SDK(require restart) under Tools--> Options-->Environment-->Preview Features.
a) If you have VS2019 at your agent, just update it to the latest version so that you will get the latest version about MSBuild.
b) Download the latest version of Build Tool for VS2019. You can download it under Tools for Visual Studio 2019 from this link. If you have already downloaded it, please update it to the latest version in vs installer. Also, make sure that you have install the workload Net Core build tools. After that, you can build net core projects with it.
3) Then try to run .\restore.cmd in developer command prompt.
I'm trying to develop a simple web app using .Net Core 3.0 on an Ubuntu machine.
I setup the .Net Core SDK and the runtime from this link. I setup VS Code and then I create a project using the following commands dotnet new webapp -o RazorPagesMovie code -r RazorPagesMovie
I built the project and it is working. But in VS Code, it shows the following error:
The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
screenshot of vs code
Regarding your problem, there are multiple open issues on omnisharp-vscode (e.g. 3289, 3290) GitHub repository. A few workarounds are available as follows:
For Windows: install Visual Studio 2019 Community Edition, or MsBuild Tools 2019
For Linux/MacOS: install Mono 6.0.0 or newer
Or uninstall the previous versions of .NET Core. If you don't like these workarounds, the best solution to fix the issue is that installing the new (beta) OmniSharp build for the time being.
You can install this build by adding the following line into your VS Code settings.json:
"omnisharp.path": "1.34.4-beta.7"
Once you save the settings, the new build of omnisharp-vscode with fix will be installed. After the installation, restart IDE if required. I can confirm that the fix works for Windows.
I often get a similar message on .net core 2.x and I find that you have to add the reference to netstandard into the project file to fix as below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
..
</PropertyGroup>
<ItemGroup>
..
</ItemGroup>
<ItemGroup> <Reference Include="netstandard" /> </ItemGroup>
</Project>
On Mac I tried removing old dot net runtimes and sdks, using the preview version of omnisharp and verifying mono version above 6.0.0
I also deleted project bin and obj dirs, recompiled, deleted nuget cache dirs and restored.
Then I ran across this in related post:
ACK! Upgrading to Mono 6.4 solves problem under Linux!
(Under Mono 6.0 problem occurs as I have had this version before)
Not 6.0 necessarily....
I'm trying to run a .NET Core application on my Windows Server 2016 instance. It builds/runs fine on my Windows 10 machine.
First I'm doing dotnet publish and I copy the published site to the Windows Server instance. I followed this guide and installed both the hosting bundle as well as the latest SDK (2.1.3).
However when I try to dotnet myapp.dll i get the following error message:
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.All', version '2.1.1' was not found.
- Check application dependencies and target a framework version installed at:
C:\Program Files\dotnet\
- Installing .NET Core prerequisites might help resolve this problem:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
- The following versions are installed:
2.1.0 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
I can see clearly that indeed Microsoft.AspNetCore.All only has a 2.1.0 version located in Program Files\dotnet\shared. How do I get the correct 2.1.1 version?
Any guidance is highly appreciated.
Use this link to install 2.1.1 core sdk version:
https://github.com/dotnet/versions/tree/7a833dddfddc27f2074b755b94234a25b9757637/build-info/dotnet/product/cli/release/2.1
Looks like there's been some issue with publishing the Microsoft.AspNetCore.All package, and it is not set to automatically install with VS update/Core SDK install. At least not for me. The nuget package was also added just 10 hours ago with 0 downloads. So by default we're still stuck with 2.1.0. To fix this, the first thing I did was to check what the ASP.NET web app templates use (they keep changing the defaults, so if you have an old project you're updating, it's always handy to check changes in default templates too).
The fix for me was removing the Version parameter from the tag in the .csproj file, as is now done in the default template. Original:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.1" />
</ItemGroup>
After modification:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" />
</ItemGroup>
This will essentially resolve to the latest installed version, i.e. 2.1.0 for now. Most likely 2.1.1 will be installed in the later updates. You could also try installing the latest package manually, but I recommend to resorting to default when possible. This way it's less likely that future updates will break my system.
You have two options:
Install the 2.1.1 framework on the server (as mentioned in another answer)
Publish your app with all the required assets. You can do this with the following command:
dotnet publish --self-contained
I'm have an an ASP.NET Core application that was created using Visual Studio 2017 on Windows 10. It works as expected running the following commands
cd src
dotnet restore
dotnet build
cd Hello.Portal
dotnet run
See build.cmd in the repository for more details.
My next objective is to create a build.sh for RHEL 7, which would end up with an RPM (but that is outside the scope of this question). To prepare for that I did the following:
Create an RHEL 7.3 virtual machine in VMware Workstation
Followed the instructions to install dotnet core 1.1 in the VM.
I then ran the following commands on Windows 10 to create a self-contained deployment.
dotnet restore --runtime rhel.7-x64
dotnet publish --framework netcoreapp1.1 --runtime rhel.7-x64
I then SFTP the output over to the VM and the application works as expected.
I then cloned the GIT repository to the RHEL VM and then ran the following commands, assuming that it would work the same way it did for Windows.
cd src
dotnet restore
dotnet build
However it failed with the following errors:
[werners#localhost src]$ dotnet restore
warn : The folder '/home/werners/development/hello/src' does not contain a project to restore.
[werners#localhost src]$ dotnet build
Couldn't find 'project.json' in current directory
[werners#localhost src]$
This looks rather suspicious. So I logged out and logged back in and the ran the following commands:
[werners#localhost ~]$ scl enable rh-dotnetcore11 bash
[werners#localhost ~]$ dotnet --version
1.0.0-preview2-1-003176
On Windows, the version returns the following:
S:\hello\src>dotnet --version
1.0.3
So it looks like rh-dotnetcore11 doesn't have the latest released version of .NET core command line.
To validate, I ran the following as root.
[root#localhost ~]# yum install rh-dotnetcore11
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
Package rh-dotnetcore11-1.0-1.el7.x86_64 already installed and latest version
Nothing to do
What instructions does one follow to use Red Hat Enterprise Linux 7.3 to build, test, run and publish ASP.NET Core application that was created with Visual Studio 2017? .
So it looks like rh-dotnetcore11 doesn't have the latest released version of .NET core command line.
It doesn't. The original release of .NET Core 1.0 had an RC version of CLI (or the SDK, if you will). This was packaged as rh-dotnetcore10 (and later an updated version was rh-dotnetcore11).
Due to compatibility requirements, RHEL packages can not break the command line interface and API.
The 1.0 SDK changed how the command line behaves and the project format; as such it was not suitable for inclusion into RHEL since it would break people's existing workflow and require migration from project.json to csproj.
As such, the RHEL packages contain the latest APIs (corefx and/or coreclr) but the older RC-era SDK.
What instructions does one follow to use Red Hat Enterprise Linux 7.3 to build, test, run and publish ASP.NET Core application that was created with Visual Studio 2017?
Unfortunately, there's no good path forward right now. Some options include:
Using an upstream install of dotnet, something which won't be supported by Red Hat since it's not the official Red Hat package: https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh
Use the RC version of the SDK on Windows, Visual Studio 2015 (2017 doesn't support project.json) and rh-dotnetcore11 on RHEL.
Wait a bit for 2.0 (hopefully releases soon) which should have the new SDK since Red Hat does not aim for compatibility between 1.0 and 2.0.