ASP.NET Core 2.0 all the references inside the `startup.cs` are raising errors - visual-studio

I use to have any ASP.NET Core MVC web project version 2.0 project working well inside visual studio 2019,.
But when i opened the project inside a new development machine using visual studio 2022 >> i started getting these errors inside the startup.c,and all the references inside the startup.cs are raising errors:-
any advice on this please?
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<UserSecretsId>****</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\file\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
</ItemGroup>
</Project>

Related

How to run T4 template in Blazor project on build

I have a Blazor project with a T4 template I wrote for scaffolding some code automatically. It works great from within Visual Studio, but I have to modify & save the template to get it to run again (as documented and expected).
I also want to run the template when building the project, so instead of VS running the template, it has to be MSBuild. I went through a bunch of articles about the topic and it looks like I have to re-import the default targets, as explained here.
I added the following to the top of my .csproj file, and this is when things went south:
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.Web" />
This is the error I'm getting:
The TargetFramework value 'netstandard2.1' was not recognized. It may
be misspelled. If not, then the TargetFrameworkIdentifier and/or
TargetFrameworkVersion properties must be specified
explicitly. TestProject C:\Program
Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets 93
Full .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.Web" />
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
</ItemGroup>
</Project>
What am I missing/doing wrong?
You should note the info from the article:
Fortunately, there’s a workaround: you can import the default targets
file explicitly, and import the text templating targets after that:
Solution
You should import those targets after netstandard 2.1 node.
In my side, I use these:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.Web" />
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets"/>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build"
Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer"
Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0"/>
</ItemGroup>
</Project>
Then,

.NET core output type in csproj file

I have a csproj file made on a Windows machine that uses .NET SDK. I am currently using the file on a Mac and want to know what the project SDK should be for .NET Core 2.2 and want to know what the output type should be for a Mac.
The .csproj file is support multi-platform. You need the sdk that defined in TargetFramework and above
The csproj file is:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\vtortola.WebSockets.Deflate\vtortola.WebSockets.Deflate.csproj" />
<ProjectReference Include="..\..\vtortola.WebSockets.Rfc6455\vtortola.WebSockets.Rfc6455.csproj" />
<ProjectReference Include="..\..\vtortola.WebSockets\vtortola.WebSockets.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
<Folder Include="Properties\" />
</ItemGroup>
</Project>
I want the project sdk on top to indicate that I am using .net core 2.2. Also, since I am building on a mac I want to know what the output type should be...I think the target framework is correctly showing .net core 2.2
Thanks

Angular-cli project, hosted inde a Visual Studio Core 2.2 Web Api project, fails to compile, randomly

I have a Visual Studio 2017 ASP.NET Core 2.2 project based on the API template.
Inside the Api project I have created a new angular-cli based web application.
Visual Studio Build fails to compile randomly. Build fails. Then I compile again without changing anything and the build completes successfully. If I build again, it will now compile consistently but with warningss, and suddenly it will start fail again with same errors and repeat.
When it fails I get 24 build errors similar to this. It package folder under nodes_modules.
TS2420 Build:Class 'MockMediaQueryList' incorrectly implements interface 'MediaQueryList'. C:\somePath\node_modules\#angular\flex-layout\core\typings\match-media\mock\mock-match-media.d.ts
When it compiles I have 8 warnings like this:
C:\somePath\node_modules\#angular\flex-layout\core\typings\match-media\mock\mock-match-media.d.ts(62,22): error TS2420: Build:Class 'MockMediaQueryList' incorrectly implements interface 'MediaQueryList'.
I am not aware of anything that is doing any operations on the files under node_modules at compile time. The angular-cli app should be completely ignored by MsBuild, but it is clearly not.
Under "project properties" --> "Typescript build" I have selected "Use latest available" and removed the checkmark in the "Enable" checkbox.
This is my project.csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>
<ServerGarbageCollection>True</ServerGarbageCollection>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<TargetLatestRuntimePatch>False</TargetLatestRuntimePatch>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.ServiceFabric.AspNetCore.Kestrel" Version="3.3.617" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptTarget>ES2015</TypeScriptTarget>
<TypeScriptJSXEmit>None</TypeScriptJSXEmit>
<TypeScriptModuleKind>ES6</TypeScriptModuleKind>
<TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
<TypeScriptRemoveComments>True</TypeScriptRemoveComments>
<TypeScriptOutFile />
<TypeScriptOutDir />
<TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
<TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
<TypeScriptSourceMap>True</TypeScriptSourceMap>
<TypeScriptMapRoot />
<TypeScriptSourceRoot />
</PropertyGroup>
</Project>
The problem was resolved by upgrading to the latest version
npm install #angular/flex-layout#latest

the runcommand property is not defined on ASP.NET Core 2

In Visual Studio 2017, I got an error in all projects that are related with ASP.NET Core 2 .
That says:
unable to run your project. the runcommand property is not defined
Even I uninstalled the VS and again installed it but I have still this problem.
I tested default project template for VS but those do not execute right, too.
Please help me.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Folder Include="Views\Product\" />
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.1" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
</Project>
netcoreapp2.0
Try changing to:
netstandard2.0

How to change “Class Library Project” into “Test Project"?

While working on ASP.NET MVC3 application, by mistake I have added a Class library as a Unit Test project. But unfortunately I don’t see the "Run Tests" from context menu to test the methods which are created for unit testing .
Is there any way to convert the “Class Library Project” into a “Test Project” ?
There is a property type guid in the project file.
Look at this post: How does Visual Studio /mstest identify test projects?
add Microsoft.NET.Test.Sdk from nuget
What worked for me was to do add this <PropertyGroup> tag with this libraries to my project (.csproj or .vbproj) file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>
<!--Here goes any other configuration-->
</Project>

Resources