I am building an ASP.NET Core app for WebAPI and I have a regular .NET class library containing my object model. Is there an easy way to reference that in my ASP.NET core app? I tried doing "Add Reference" and pointing to the dll in our release folder (this is how we normally go about adding references) but that gave me an error stating that only .NET assemblies could be referenced. It is a .NET assembly (.NET 4.61 - my ASP.NET Core app is targeting the full framework - also .NET 4.61). I also tried adding the existing project to my solution and referencing it as a project reference. This will add it to my project.json but I get an error that it can't resolve the reference. I did follow this guide and it gave me the same error - could not resolve reference. It doesn't seem like it should be this hard to get this to work. I would imagine that most developers would want to abstract their object model out from a particular web app and be able to reference it. At this point, I'm not using anything crazy. I just have a collection of interfaces using standard .NET types. Though down the road I also want to be able to add references to COM libraries (I'm not exactly confident right now that that is going to work). If anyone has any insight for me, it would be much appreciated.
Thanks.
Related
I have 2 projects in my solution - .Net Maui(GUI) and ASP.Net Core Web API(API)
After adding a project reference to my GUI I get the following errors:
And I can find very little information on that, although I'm probably looking in wrong places. Can you give a hand with that?
Edit:
To complete/expand my question, I'm looking for a way to structer my solution a little bit better, I don't want to have everything in .NET Maui project.
I was following this tutorial https://www.youtube.com/watch?v=LrZwd-f0M4I
The author does create .NET Core project for API and Db connection
(EF Core) and then he uses the Api in .NET Maui
What am I missing?
I'm trying to create a shared class library using .Net Standard 2.0 which will be used by both Asp.Net Core MVC (2.1) as well as Asp.Net MVC on .Net Framework 4.5+. This is fine for my model classes and I'm able to resolve all the api's that I require so far. However, I now need to create the shared, partial view that uses the model but I can't seem to find anything useful out there to describe what nuget packages I should reference etc. When I create the .cshtml view I can't resolve #model
I've tried adding the Microsoft.NET.Sdk.Razor nuget package but it didn't work and I feel I'm missing some essential documentation that explains this better. If anyone has any ideas, please point me in the right direction or tell me if this is impossible from a .Net Standard project.
EDIT: Let's forget about .Net Standard. Is it possible to create a razor view that can be used by both .Net Core and .Net Framework?
I'm looking to apply aspects to all types within my .NET Core 2.0 project. The examples given on the PostSharp site all speak about the AssemblyInfo.cs file, but that does not exist for .NET Core projects.
I have tried putting the configuration into the .csproj file as suggested here but this does not allow me to pass in a non-string parameter, and I need to set the AttributeTargetTypes value prior to the string constant.
Has anyone managed to get this working for .NET Core 2.0? This is my first time using PostSharp and I am hopefully missing something obvious.
Having returned to this, the main problem I appear to have had was that that I needed to reference the PostSharp nuget package in the consuming project as well as in the project holding the aspect. Once that was done the aspect worked as expected, and then as Daniel mentioned above I created a new .cs file with the aspect reference and this binded the attribute to the necessary classes.
Background
I am working on a reasonably large legacy ASP.NET MVC solution.
Currently all of the code resides in just two projects (one containing model first C# generated code, the other containing the rest of the application).
Problem
I've added 2 projects to the solution - one for unit tests & one containing some code to be used as a service by the web application.
When I reference the service project from the main project there's a yellow warning sign by the reference.
As I said this is a legacy project with code all over the place & I'm not sure why this is happening.
I've tried Googling for a solution but haven't been able to find anything that gives some clues to this problem...
Note: There are just two classes in the service project
Here's a picture of the warning:
Make sure that both projects are set to the same version of the .NET Framework.
For example if your Main project targets to .NET Framework 4.0 and your Services project targets to .NET Framework 4.5.2, you can expect some compatibility issues.
I've added a new Class Library (Package) project to my solution. It's my first experience with a .NET Core (or whatever I'm using, still confused)
My class library contains two references: .NET Framework 4.5.1 and .NET Platform 5.4
I'm trying to import some code from a sample project that uses IPrincipal. For some reason it's saying that it doesn't exist on namespace "System.Security" altohugh I can get it trough intellisense.
What's wrong with my project settings?
The new feature of .NET Core and Class Library (Package) is that it targets multiple platform and will compile into multiple assemblies which get automatically packaged into a nuget package.
When your class library targets multiple targets, it will compile to all of them. So if a certain library is only available on full .NET framework but not on .NET Core or other target framework, then you may receive intellisense if your editor is set to .NET 4.5. More information can be found in my other recent answer.
You can switch back and forth with the pull down menu on top left of the coding window, show in the screenshot below.
If you do not want to target a certain framework, you have to remove it's moniker from the project.json file or use preprocessor directives to write platform specific code or libraries/replacements.
.NET Core is heavily modularized and most of only the core modules are referenced in the default project and if you need additional one you need to reference them within the dotnet5.x section.
Basically you have multiple places with "dependencies" in your project.json, a global one where you can add dependencies which are available on all targeted frameworks and one within each "frameworks" section for each of the targets only.
Though the other answer covers some basic concepts, it would require some attention on which classes are available and which are not.
Microsoft temporarily host a web site at http://packagesearch.azurewebsites.net to assist.
If you can find a suitable package for RC1 from there, then you can add it to your project.json file. If not, you will have to conditional compile it to a desktop profile or use other alternatives.