How to add Identity Scaffolding to an ASP.NET CORE Applicationon using Rider IDE - visual-studio

I'm watching a tutorial about ASP.NET CORE Identity,In it the instructor add identity by scaffolding it using Visual Studio, but right now I'm using Rider IDE and i'm not seeing such option on it, so i believe is a exclusive feature of Visual Studio.
So is there a way to implement it on Rider IDE? or I'm forced to do it on Visual Studio and then come back to rider again?

From the Terminal in Rider (default located at the bottom of the IDE) you can run the following commands (Full Reference).
dotnet tool install -g dotnet-aspnet-codegenerator
If you've already got the dotnet-aspnet-codegenerator tool installed, you may need to update it:
dotnet tool update -g dotnet-aspnet-codegenerator
Make sure you're switched in to the project directory if not already (not the solution root, cd ProjectName.
Then install the Microsoft.VisualStudio.Web.CodeGeneration.Design package either via the NuGet tab, or the command line (dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design).
Then run the following to generate default project:
dotnet aspnet-codegenerator identity
The Identity Area will be populated with both Data and Pages folders in your project.
A real world example (with an existing DbContext and using Sqlite) is:
dotnet aspnet-codegenerator identity -dc ApplicationDbContext -gl -sqlite -f

Related

Assets file project.assets.json doesn't have a target for 'net6.0' - VS2022

Just a few days ago got this error, after updating to Visual Studio Community 2022 v17.2 (from v17.1.6):
Error NETSDK1005
Assets file 'C:.........XXXXXX.Web\obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project. XXXXXX.Web C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 267
Uninstalled everything related with VS2022 + Installer
Rebooted
Fresh Git Cloned the project I'm working on (I work on several computers all with Win 10 and all with the latest updates, this is the only VS installation that presents this problem)
Reinstalled VS 2022 v17.2 (with .NET 6.0, the usual install)
The .csproj file has everything in place:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);(SpaRoot)\**\node_modules\**;</DefaultItemExcludes>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>
Always delete the 'bin' and 'obj' folders before build or rebuild....
Cannot get away with the compilation, and always receiving that NETSDK1005 error...
Getting desperate :(
Thanks in advance for any help
P.S. - already checked question 70711153
I found the problem and it indeed had to do with restoring NuGet Packages, in that I have a connection to a corporate NuGet repository, and the call to it was breaking due to wrong credentials.
What was troubling was that the error did not identify the nature of problem with the connection or the username of the credentials getting refused.
On the logged in user popup dialog window, where the several used usernames are presented, there was one username that was required to re-enter its password.
That was all it took.
Visual Studio > Tools > Options > Azure Service Authentication. ReBuild and the NuGet Packages will be restored and build successful.
We had this issue in our Azure DevOps pipeline and it ended up being that the "NuGet Restore" task was using an old version of NuGet. You can see which version the pipeline is using if you check the logs for the "NuGet Restore" task and look for the "Detected NuGet" line.
We:
added in the "NuGet Tool Installer" task before the "NuGet Restore" task
Under the "Version of NuGet.exe to install", list the version you want to use, or the minimum version (e.g. >=6.1.0)
(this step is possibly overkill) Under the "NuGet Restore" Task, check "Disable local cache"
This happens because NuGet writes a file named project.assets.json in the obj\ folder & the .NET SDK uses it to get information about packages to pass into the compiler. In .NET 5, Nuget added a new field called TargetFrameworkAlias, and thus in MSBuild versions < 16.8 or NuGet versions < 5.8, it is possible that you can generate an assets file without the TargetFrameworkAlias as it will read the property and not find it.
You can resolve this issue by ensuring you are on MSBuild version 16.8+ & using NuGet version 5.8+.
In my case I have commented out the TargetAlias line and it published successfully.
Reference: https://developercommunity.visualstudio.com/t/error-netsdk1005-assets-file-projectassetsjson-doe/1248649
For me, I was getting this when updating my projects from .NET Core 3.1 to .NET 6. I had my .NET 6 code in another Git branch and when I switched from the main 3.1 branch to the 6 branch and then tried to build the solution, I would get that message.
After some trial and error, the solution that worked for me was doing the Git checkout and the restore via command line.
Close the solution
From the Developer Powershell (or using regular Powershell or the Visual Studio 2022 Command Prompt), navigate to the local directory that has your repo, and then:
git checkout [branch name]
dotnet restore
Then back in Visual Studio, reopen the solution and build, which would work.
For me, this happened after switching from .net6.0 to .net 7.0 in asp.net core / blazor project. The error occured when trying to publish the project to IIS.
Solution was to switch the "target framework" in the publishing configuration (.pubxml) in the "Publish"-tab.
For me this fix worked:
If you don't have the dotnet cmd line tool, download and install the .NET 6 SDK.
Open a cmd prompt and run the command:
dotnet restore <path to your solution>
(for instance: dotnet restore c:\app\myapp.sln)
nuget restore resolved the same issue
and/or dotnet restore
I had this bug in a solution with several SDK plus non-SDK C# projects.
What fixed my case:
Close the solution.
Separately open the first project of the solution that Visual Studio failed to build.
Build the project. --> "Error not found and build is OK"
Reopen solution. --> "Error disappeared"
I got the same error when publishing Web API to the cloud.
Use Tools ->Command line -> Developer command prompt in Visual Studio 2022, enter AZ login, and after login, restart the visual studio, it is working for me again.
Had the same problem in Azure Devops, using a Windows 2019 build server with VisualStudio 2022
Error:
##[error]C:\Program Files\dotnet\sdk\6.0.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): Error NETSDK1005: Assets file 'C:\agent\vso_work\4\s<..>.API\obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project.
Resolved by adding a "NuGet Tool Installer" using version >=6.0.0
Before the NuGet restore task
enter image description here
we got this problem when added cache on gitlab, and started to use dotnet restore,
it happend because we missed the "runtime" parameter to the restore command,
- dotnet restore --packages .nuget --runtime win-x64
- dotnet publish --no-restore --runtime win-x64
In my case the problem was I had updated the Nuget package version in one assembly but not in another, so check you have the same nuget package versions across your solution.
For me, it works to set the target framework to another framework like .NET Core 3.1, build the application, set the framework to the original framework and rebuild.
In my case I had inadvertently added a couple of projects to the solution that were in another folder. I received no errors until I changed NET version from NET6.0 to NET6.0-windows on one of the projects. The solution then didn't build, with 100s of errors, but each individual project built OK.
I noticed that "project.assets.json' doesn't have a target" error among all the errors, pointing to the outside folder.
Bringing those projects into the solution folder fixed the error.
I got the same error sometime back. This worked for me: Logout from visual studio and login to visual studio account
I had an error:
Ensure that restore has run and that you have included 'net6.0' in the
TargetFrameworks for your project. You may also need to include
'win10-x64' in your project's RuntimeIdentifiers.
I removed bin and obj folders for this project and rebuilt the project. dotnet clean, dotnet restore didn't work for me.
I had the same problem ("...\obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore...") with clean batch compilation of my sln: msbuild 17.4, nuget 4.7.
I replaced string
nuget.exe restore my.sln
with string
msbuild.exe my.sln /t:Restore
that was before
msbuild.exe my.sln /t:Build
and everything worked.
I got the same error this morning.
This worked for me: right click on solution explorer in visual studio -> 'Restore NuGet Packages'.
Hope this helps.

Visual Studio Mac, build from command line?

I'm considering using Visual Studio and Xamarin to build a cross-platform app but I prefer to use Sublime Text as my editor. Currently I can't find any information on 3rd party tool integration with Visual Studio.
Does Visual Studio have any way to build from the command line like Xcode does using the "xcodebuild" utility? Ideally I want to make a shell script which can build as if I pressed the build button in VS and return errors I can parse and display in Sublime Text.
Any suggestions are greatly appreciated.
We've use the command line like the following:
msbuild /p:Configuration="AppStore" /p:Platform="iPhone" /p:IpaPackageDir=bin/iPhone/AppStore /p:BuildIpa=true /target:xxxxxxx.sln
Finding doco for what options are required has taken time via Google. Hope this helps.
I use 'vstool' located at "/Applications/Visual Studio.app/Contents/MacOS/vstool" this way:
vstool build -t:Build -c:"Release|iPhone" "MyProject.sln";
As mentioned in vstool help:
Visual Studio Build Tool
build [options] [build-file]
-p --project:PROJECT Name of the project to build.
-t --target:TARGET Name of the target: Build or Clean.
-c --configuration:CONFIGURATION Name of the solution configuration to build.
-r --runtime:PREFIX Prefix of the Mono runtime to build against.
Supported targets:
Build: build the project (the default target).
Clean: clean the project.

Visual Studio 2017 - How to create a project from the source using CMake?

I have a pretty large software library using CMake to be compiled. We use Linux mostly, but now a new colleague wants to use Visual Studio.
Is there any way to create a new VS 2017 project from the existing source codes with CMake structure?
I know, it's possible to do it with CLion, but I have no idea about VS, as I have a very little experience with it.
Other questions seem to focus on creating an empty project, which will use CMake, but not on creating a project from already existing source files.
Creating a cmake project with visual studio
Creating a project with visual studio 2017
I'm not sure why you asked for details but...
Assuming you are using cmake 3.13 then you can do the following in a command shell:
cmake -G "Visual Studio 15 2017" -S path_to_source -B path_to_build
This will then create a solution file. Actually it creates a solution file for every project() command that is issued in CMakeLists.txt.
You can then open the solution file in Visual Studio, and build the project as usual.
You don't even need to do this in the Visual Studio GUI. After creating the initial project you can also issue the command:
cmake --build path_to_build
Which will kick off the build at the command line.
Now if your CMakeLists.txt in path_to_source is using Linux specific libraries or gcc specific compiler settings then the CMakeLists.txt will have to get updated to the Windows equivalent.
The alternative is to start Visual Studio and then use File->Open->CMake and open the CMakeLists.txt file in path_to_source. It'll then start to generate the project. But I prefer using the command line method.

Xamarin vstool build cannot find NuGet MSBuild targets

Background
I recently converted my Xamarin.Forms app from PCL to Net Standard format.
All of my projects now use PackageReference in the csproj file. Which means no more package.config or package.json.
We use TFS 2015 to build, sign, package our .ipa and .apk files. After conversion, the default MSBUILD build steps do not work as they look for mdtool and the new Visual Studio has vstool instead. So, I updated the build steps to use new tools via command line.
All my projects are NetStandard now (including iOS and Android).
Issue
I can successfully restore NuGet packages using restore MySolution.sln -force on Mac build server. But when I run vstool build MySolution.sln after that, I get this error:
error: NuGet packages need to be restored before building. NuGet
MSBuild targets are missing and are needed for building. The NuGet
MSBuild targets are generated when the NuGet packages are restored.
I am able to successfully run the nuget restore and vstool build locally on the build machine. But only when TFS runs the command via agent, it shows that error message.
Setup
Builds: TFS 2015 on Mac agent running Visual Studio 7.5
According to the error and your description, you need also check if your build agent has corresponding capability to support vsbuild.
Take a look at this related question MacOS - Visual Studio Support and give a try with this workaround:
As a work around we set the Xamarin.iOS variable manually in the build
agent and changed the mdtool path in the Xamarin iOS Build step to
"/Applications/Visual Studio.app/Contents/MacOS/vstool".
Besides you could also try to use the suggestion from Matt in the comment above.
Ok. I was finally able to get a successful iOS build on Mac server. This is the setup that works,
Using PackageReference in iOS .csproj
No package.config, project.json, or AssemblyInfo.cs file.
Running nuget restore .sln before building the iOS project.
Build solution using <path-to-vstool>\vstool build .sln -c:<configuration>
Now, I am working on the Windows machine for Android setup. Once I have that working, I will post my findings here.

How can I install and use Entity Framework Core in Visual Studio Code?

I have already created the initial asp.net mvc web application template in visual studio code.
And I can run the application in a browser at localhost:5000/
I can also see the views, controllers, viewmodels like the previous asp.net mvc core.
Now, how can I install and use entity framework core using visual studio code?
Thanks.
VS Code is just an editor. It doesn't install EF (or any packages). You can install EF by editing your csproj file to contain this set of lines.
<ItemGroup>
<PackageGroup Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
</ItemGroup>
VS Code may give you a prompt to "restore" pacakges. If not, call dotnet restore on command line.
Alternatively, on command line you can execute:
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
See the "Getting Started" guide for more details on EF. To use EF, you need to write code. A full example is beyond the scope of a good StackOverflow answer and is subject to change as EF Core continually updates.
1st :
You need three line of code to install EntityFrameWork core and its dependencies.
2nd :
install them in this form
dotnet add package Microsoft.EntityFrameworkCore -v 2.1.14
dotnet add package Microsoft.EntityFrameworkCore.tools -v 2.1.14
dotnet add package Microsoft.EntityFrameworkCore.SqlServer -v 2.1.14
I put a sample of them with version but you can get latest entityframework version if you remove version in last of line.
like this.
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.tools
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
3rd
Remember your .Ner Core version should be compatible with lastest version of EntityFrameWork core which you want to install.So if you have error either you have to install lastet version of .Net Core or install EntityFrameWork core with a compatible version with .Net Core.
Probably you are looking for EntityFrameWork core version here and also for .net Core version here
To be able to use entity framework in visual code you can use yeoman on the terminal:
>npm install -g yo
>npm install -g generator-efrepo
>yo efrepo
Then follow the instructions
In addition to answers given above, following article has all the steps for adding EF Core using .Net Core CLI.
Getting Started with EF Core
Hope this helps to someone.
*Edit:
- VS Code users can execute dotnet commands from Terminal window (Ctrl+Shift+`)
I think this is the updated link, as of June 3.
https://docs.efproject.net/en/latest/
In my case i had deleted the "csproj" by accident, after research a lot, i knew about this possibility and found the deleted file in my trash.

Resources