Why is Winforms template missing from my .NET 7? - c#

I have a Linux laptop and there is already installed .NET. This is result of dotnet --list-sdks command line:
5.0.404 [/usr/share/dotnet/sdk]
6.0.101 [/usr/share/dotnet/sdk]
6.0.404 [/usr/share/dotnet/sdk]
7.0.101 [/usr/share/dotnet/sdk]
and I have global.json file in my CWD like this:
{
"sdk": {
"version": "7.0.101",
"rollForward": "latestFeature"
}
}
But when I am running dotnet new winforms command in my terminal I get this response:
No templates or subcommands found matching: 'winforms'.
How can I fix this problem?

Related

JetBrains Rider puts global.json by default which cannot be resolved

Once I create a project in JetBrains Rider, it puts global.json by default and it is unable to resolve the .NET SDK version.
Why?
Microsoft.NET.Sdk.DefaultItems.targets(127, 5): [NETSDK1141] Unable to resolve the .NET SDK version as specified in the global.json located at C:\Users\user\Desktop\Nick Chapsas Elfocrash\basic-sources-master\ASPNETCoreTutorials\ResultVideo.Api\global.json.
{
"sdk": {
"version": "6.0.0",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}
You can look up the error code: https://learn.microsoft.com/en-us/dotnet/core/tools/sdk-errors/netsdk1141
You most likely don't have .NET 6.0 SDK installed.

zsh: command not found: dotnet-ef

I am using asp.net core 2.1 with visual studio code or rider in mac. I already have a 2.1 sdk install on mac, while using the below command
dotnet-ef database update --project XXXX.XXXX
I get an exception as
zsh: command not found: dotnet-ef
Using the command
dotnet tool install --global dotnet-ef
getting an exception as Tool 'dotnet-ef' is already installed.
Then using this command dotnet tool restore
error NU3037: Package 'dotnet-ef 3.1.1' from source 'https://api.nuget.org/v3/index.json': The repository countersignature validity period has expired.
Package "dotnet-ef" failed to restore, due to Microsoft.DotNet.ToolPackage.ToolPackageException: The tool package could not be restored.
For mac I need to export the below path
export PATH="$PATH:$HOME/.dotnet/tools/"
Yes, give an example of the error:
$ dotnet ef
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
The second and third refer to dotnet trying to find a dotnet-ef command but it cannot find it. As the third point said, dotnet-ef is not on your way.
This is what the documentation says:
Global tools can be installed in the default directory or in a specific location. The default directory is:
OS Path
Linux/macOS $HOME/.dotnet/tools
Windows %USERPROFILE%\.dotnet\tools
So, you should add $HOME/.dotnet/tools/ to your $PATH.
For Linux and macOS, add a line to the shell configuration:
bash/ zsh:
export PATH="$PATH:$HOME/.dotnet/tools/"
When you start a new shell/terminal (or next time you log in) dotnet ef should work.
For Windows:
You need to add %USERPROFILE%.dotnet\tools to PATH.
I am using asp.net core 6.0
zhengguo#macdeMac-min % echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
The PATH has already exist ~/.dotnet/tools
When I use dotnet aspnet-codegenerator, it works. dotnet-aspnet-codegenerator not work.

'dotnet build' command not finding NuGet packages (they exist)

I'm trying to build my .NET Core 2.1 application from the command-line on my Jenkins server.
It builds fine on my local machine (Windows 10, Visual Studio 2017 Enterprise), and if I manually build it on the server Jenkins is running on (manually checkout Git repository and running dotnet build). It's only when I'm doing it through Jenkins in a Docker container that it fails.
The error:
/usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.CodeQuality.Analyzers, version 2.6.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj]
The package exists in ~/.nuget/packages/.
I'm aware my Jenkinsfile is a bit weird at the moment, but that has to do with me trying to make this all work. It seems dotnet restore is working fine, but dotnet build is somehow not locating these files.
I've tried specifying the package directory (through the environment variable, with dotnet restore --sources and dotnet build --sources.
I attached pretty much anything I could think of at the moment, but if I forgot something please tell. I'm pretty lost at the moment.
My Jenkinsfile:
pipeline {
agent {
docker {
image 'microsoft/dotnet:2.1-sdk'
}
}
environment {
HOME = '.'
NUGET_PACKAGES = './.nuget/packages/'
}
stages {
stage('pre-build') {
steps {
// logging tooling versions
sh 'dotnet --info'
sh 'find ~/.nuget/packages/microsoft.codequality.analyzers/ -type f'
sh 'dotnet nuget locals all --list'
sh 'dotnet restore'
// sh 'dotnet clean'
}
}
stage('build') {
steps {
// sh 'dotnet restore --force --no-cache'
// sh 'ls ./packages/'
// sh 'find ./packages/microsoft.codequality.analyzers/ -type f'
sh 'dotnet build --no-restore'
}
}
stage('test') {
steps {
sh 'no test project configured'
// sh 'dotnet test'
}
}
}
}
My .csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet></CodeAnalysisRuleSet>
<Features>IOperation</Features>
</PropertyGroup>
</Project>
Some build details:
$ docker --version
Docker version 18.06.1-ce, build e68fc7a
Inside docker container:
$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.403
Commit: 04e15494b6
Runtime Environment:
OS Name: debian
OS Version: 9
OS Platform: Linux
RID: debian.9-arm
Base Path: /usr/share/dotnet/sdk/2.1.403/
Host (useful for support):
Version: 2.1.5
Commit: 290303f510
.NET Core SDKs installed:
2.1.403 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
$ find ./.nuget/packages/microsoft.codequality.analyzers/ -type f
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/vb/Microsoft.CodeQuality.VisualBasic.Analyzers.dll
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/vb/Microsoft.CodeQuality.Analyzers.dll
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/cs/Microsoft.CodeQuality.Analyzers.dll
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/cs/Microsoft.CodeQuality.CSharp.Analyzers.dll
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/.signature.p7s
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/ThirdPartyNotices.rtf
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/build/Microsoft.CodeQuality.CSharp.Analyzers.props
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/build/Microsoft.CodeQuality.VisualBasic.Analyzers.props
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/build/Microsoft.CodeQuality.Analyzers.props
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DesignRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DocumentationRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/PerformanceRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/UsageRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/ReliabilityRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/MaintainabilityRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/SecurityRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/PerformanceRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/MaintainabilityRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/UsageRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DocumentationRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/ReliabilityRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/AllRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/NamingRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/AllRulesDisabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/SecurityRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DesignRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/NamingRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/AllRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/microsoft.codequality.analyzers.2.6.2.nupkg.sha512
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/microsoft.codequality.analyzers.2.6.2.nupkg
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/microsoft.codequality.analyzers.nuspec
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/tools/uninstall.ps1
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/tools/install.ps1
$ dotnet nuget locals all --list
info : http-cache: ./.local/share/NuGet/v3-cache
info : global-packages: ./.nuget/packages/
info : temp: /tmp/NuGetScratch
info : plugins-cache: ./.local/share/NuGet/plugins-cache
$ dotnet restore
Restoring packages for /var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj...
Restore completed in 13.5 sec for /var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj.
$ dotnet build --no-restore
Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
/usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.CodeQuality.Analyzers, version 2.6.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj]
Build FAILED.
/usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.CodeQuality.Analyzers, version 2.6.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj]
0 Warning(s)
1 Error(s)
I've resolved the issue by specifying where dotnet build should look for the NuGet packages. It that within the image it doesn't look at the right location (although I'm not sure where it is looking either...)
I've specified the location with the --packages option. This option is listed in the dotnet restore documentation, but not in the dotnet build ones, even though it is available there as well (and you need it there, specifically).
You can specify it as follows:
dotnet restore --packages <path>
and
dotnet build --packages <path>
It works with the --no-restore option as well, if you need that.
My final Jenkinsfile looks as follows:
pipeline {
agent {
docker {
image 'microsoft/dotnet:2.1-sdk'
}
}
environment {
HOME = '.'
}
stages {
stage('pre-build') {
steps {
// logging tooling versions
sh 'dotnet --info'
sh 'dotnet nuget locals all --list'
sh 'dotnet clean'
}
}
stage('build') {
steps {
sh 'dotnet build --packages ./.nuget/packages'
}
}
stage('test') {
steps {
sh 'echo no test project configured'
// sh 'dotnet test'
}
}
}
}
I ran into a similar issue solved by clearing global packages and cache with dotnet nuget locals all --clear as explained here.

System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Security, Version=4.0.0.0

I have created WebAPI project in ASP.NET Core with targeted framework dnxcore50. There are four projects in my solution.
WebAPI - Contains API methods
Core - Contains IRepository, IDataContext interfaces and base classes to communicate with Postgresql with dapper
DataAccess - Contains Repository classes for domain
Domain - Contains domain models
My application is using Postgresql database to store the data and at application side I used dapper and npgsql nuget package for database operation with Postgresql.
Everything was worked in windows environment and after that I tried in Ubuntu 14.04 and faced 'Timeout issue' while performing select query in npgsql but I resolved that by using the solution mentioned in github issue and after that everything worked perfectly in Ubuntu machine also.
So, I thought lets try to run WebAPI in docker and for that I created docker image also and successfully able to run also but unfortunately I am getting some new (compare to ubuntu 14.04) error when I call select API method which call domain repository to select data from Postgrespl by using dapper and npgsql.
fail: Microsoft.AspNet.Server.Kestrel[13]
An unhandled exception was thrown by the application.
System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Net.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load the specified file.
File name: 'System.Net.Security'
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.Open()
at Npgsql.NpgsqlConnectorPool.GetPooledConnector(NpgsqlConnection Connection)
at Npgsql.NpgsqlConnectorPool.RequestConnector(NpgsqlConnection connection)
at Npgsql.NpgsqlConnection.OpenInternal(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnection.Open()
Below are the some project.json files and docker file which used in solution.
Core project.json file
{
"version": "1.0.0-*",
"description": "Core Class Library",
"authors": [ "Jignesh" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"Dapper": "1.50.0-beta8",
"Dapper.Contrib": "1.50.0-beta8",
"Npgsql": "3.1.0-alpha6",
"System.Net.Security": "4.0.0-beta-*",
"Microsoft.NETCore.Platforms": "1.0.1-beta-*"
},
"frameworks": {
"dnxcore50": {}
}
}
Docker file
FROM jignesh/aspnet:1.0.0-rc1-update2-coreclr
RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# Add PostgreSQL's repository. It contains the most recent stable release
# of PostgreSQL, ``9.3``.
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3
# There are some warnings (in red) that show up during the build. You can hide
# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
COPY . /app
WORKDIR /app/src/WebAPI
RUN ["dnu", "restore"]
EXPOSE 5002/tcp
ENTRYPOINT ["dnx", "-p", ".", "web"]
Note jignesh/aspnet is my local docker image file which I have created for 1.0.0-rc1-update2-coreclr as hub.docker.com doesn't have that.
global.json
{
"projects": [
"wrap",
"src",
"test"
],
"sdk": {
"version": "1.0.0-rc1-update2",
"runtime": "coreclr",
"architecture": "x64"
}
}
Can someone help here ? What should I do to resolve this issue.
Let me know if more information is required.
Additional Information
dnx version information in ubuntu
Microsoft .NET Execution environment
Version: 1.0.0-rc1-16609
Type: CoreClr
Architecture: x64
OS Name: Linux
OS Version: ubuntu 14.04
Runtime Id: ubuntu.14.04-x64
dnx version information in docker
Microsoft .NET Execution environment
Version: 1.0.0-rc1-16609
Type: CoreClr
Architecture: x64
OS Name: Linux
OS Version: 8 debian
Runtime Id: ubuntu.14.04-x64
As mentioned in https://github.com/StackExchange/StackExchange.Redis/issues/350 I changed RUN ["dnu", "restore"] line to RUN ["dnu", "restore","--runtime=ubuntu.14.04-x64"] in dockerfile and issue gets resolved.
Note aspnet docker image already has line ENV DNX_RUNTIME_ID ubuntu.14.04-x64 but don't know why this only is not sufficient and required to set runtime in dnu restore.
Anyway I am happy that adding runtime in dnu restore solved my problem.

Running .NET Core on Opensuse 13.2

I have tested .NET Core on Windows & Ubuntu succesfully ( Console & ASP.NET 5 app).
I am now trying to run a simple console app, followed by a web app on OpenSUSE 13.2 x64. I have followed the tutorial found here , but with no success.
I have installed the DNX using the dnvm tool, and tried a simple hello world program:
program.json
{
"version": "1.0.0-*",
"dependencies": {
},
"frameworks" : {
"dnx451" : { },
"dnxcore50" : {
"dependencies": {
"System.Console": "4.0.0-beta-*"
}
}
}
}
program.cs
using System;
public class Program
{
public static void Main (string[] args)
{
Console.WriteLine("Hello, Linux");
Console.WriteLine("Love from CoreCLR.");
}
}
Running
dnvm list
Active Version Runtime Architecture OperatingSystem Alias
------ ------- ------- ------------ --------------- -----
1.0.0-rc1-final coreclr x64 linux
1.0.0-rc1-final mono linux/osx default
* 1.0.0-rc1-update1 coreclr x64 linux
1.0.0-rc2-16237 coreclr x64 linux
The problem is that neighter dnu restore / dnu build / dnx run does anything, it throws no error and does nothing.
According to the guys developing .NET core, this is due to an incorrect version of libicu. So, I have downloaded the source files from here and used this tutorial to build and install libicu52.1.
unzip icu4c-52_1-src.zip
cd icu
mkdir build
cd build
../source/runConfigureICU Linux/gcc CXXFLGS="-D__STRICT_ANSI__ "
make -j4
sudo make install
export LD_LIBRARY_PATH=/usr/local/lib64

Categories

Resources