Read assembly version of class library Project from .netCore web app project - asp.net-core

I have 4 web applications based on .net core. all of them call a business logic layer (class library)
i want my version to get updated on all 4 web applications.
I have tried to make a static class on my business logic layer. and on this class i have a property that gets the version as the following:
Assembly.GetEnteryAssembly().GetName().Version
i tried to call this static class from one of the applications, sadly it brings the version of the web application instead of the class library version.
I want a code that always brings me the version of class library regardless from where it is called.

You can use Assembly.GetAssembly(typeof(YourClass)), being YourClass any class within desired assembly.

You can use typeof(Startup).Assembly.GetName().Version.ToString()

Related

What is difference class library and razor class library?

I want to know What is difference.
class library vs razor class library
A Razor Class Library is use specifically for creating a set of reusable User Interface widgets that you can plug-in to multiple web apps
A Class Library is a set of usually non UI related classes, to implement a particular function/service or api. e.g. Most of the .Net libraries we use are class libraries.

Microsoft.AspNet.Identity.Owin.OwinContextExtensions doesn't seem to work

I am creating a custom asp.net.identity provider in a separate assembly in order to use it from two different web api 2 projects.
I took the default vs2013 template for a web api project as a guide and so far I have implement the required classes.
In the separate assembly I am using a user manager class derived from Microsoft.AspNet.Identity.UserManager(Of T) class.
Public Class EzeUserManager
Inherits UserManager(Of EzeIdentityUser)
Now I want to implement the create shared function in order to use as a callback in the CreatePerOwinContext function. According to the template, I am declaring it like this:
Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin
Public Class EzeUserManager
Inherits UserManager(Of EzeIdentityUser)
... Class Implementation ...
Public Shared Function Create(options As IdentityFactoryOptions(Of EzeUserManager), context As IOwinContext)
Dim Result As New EzeUserManager(New EzeIdentityUserStore(context.Get(Of EzeLDAPContext)()))
The problem is that
context.Get(Of EzeLDAPContext)()
fails because it requires a key.
From the template I can see that the get method which doesn't require a key is an extension defined in Microsoft.AspNet.Identity.Owin.OwinContextExtensions which I have already installed and referenced through nuget and imported it in the class.
But it doesn't work.
I found that the key is actually the type name of the class so probably I can overcome this problem, however I didn't try it yet because I really want to make the extensions to work.
The question is: Am I missing something here?
Notes: The project in question is a Class Library targeting .NET 4.5.1 with the following references:
Microsoft.AspNet.Identity.Core
Microsoft.AspNet.Identity.Owin
Microsoft.Owin
Microsoft.Owin.Security
Microsoft.Owin.Security.Cookies
Microsoft.Owin.Security.OAuth
Newtonsoft.Json
Owin
As I explained in the question, I was using the template generated by VS as a guide. During the implementation process of my project, I had update the nuget packages several times but only in my project not in the template project (same solution) since I was going to deleted it afterwards. This resulted the two projects to reference two different versions of the required assemblies.
I don't know how exactly and why this "multi" reference caused this problem but once I updated the template project's nuget packages the problem was resolved.
I hope this helps someone with a similar issue.

Where is the app.config

I have created a new project in Visual Studio 2013 (class library). There is no app.config. When I select add new item, there is no app.config in the list. Were is the app.config?
I have a ClassLibrary, which contains a number of NUnit Test classes. The problem is that there is lot of code like this throughout the application:
_ConString = ConfigurationManager.ConnectionStrings("GeniedbConnection").ConnectionString
Therefore when I run the tests I get a Null Pointer Exception. Is it possible to do this in the test classes:
ConfigurationManager.ConnectionStrings("GeniedbConnection").ConnectionString = "Connection String"
I get a Null Pointer Exception when I put the code on the above line into the test class. I believe it is because I am trying to set the variable before declaring it. Is that correct?
A class library doesn't contain an app config, since it isn't an app on it's own, but it can be an addition to an app. You will see an app config if you would create a winform application for example.
Class libraries are dll files that are frequently exchanged between different applications, these are often frequently used classes, that can speed up development, since you don't have to write code that you wrote once before.
MSDN Class Library
Edit:
You should use a UnitTest project and not a class library. Following question + answer will help you out, about using the .config file of your application: Use appliction config file from unittest project
UnitTest Project
If you add a reference to System.Configuration in your class library then you can use the following namespace to access the app.config of any applications which use it:
Imports System.Configuration.ConfigurationManager
...
Dim x As String = AppSettings("MySettingName")

Type of Class in C++/CLI

I am working on C++/CLI Wrapper for C Static Library.Static Library has 10 function in it.
THis C++/CLI Wrapper will Expose 10 API to C# Application.The Wrapper Will be in the Form of dll.
The Wrapper Will be Used in C# Application.
Now I am trying to add a class in C++/CLi application which will expose function to C# application I am getting Many Option like
C++ Class
CLR Class
a. Component Class
b.Installer Class
c. Windows Form
d. Installer Class
I am bit confused which I need to select out of it as I am new bee in C++/CLI
You need a
CLR Class - Component
since it can be consumed by .NET clients.
CLR class is declared as follows
ref class Wrapper {....}
However in your scenario you could also write a dynamic library and pinvoke the methods from .NET client.
Not sure if your question has been entirely answered, but a Component class creates a class that implements an IComponent interface for remoting/ inter process communication purposes. Didn't seem like what you were looking for.
I think what you were looking for i just a "template" to create a managed class?
In that case all you need to do is select C++ in the wizard and make sure the "Managed" check box on the right hand side is selected.

How to write a class library for OLE Automation?

I have Excel add-in which I add so many class modules that it is now very bulky. I want to convert it into a type library or a COM package so that I can re-use it for the other apps in the MS Office suite.
I ported the add-in to Visual Studio as a class library project but Excel Automation doesn't recognize the classes in the compiled .dll file. Intuitively I think I would need a manifest, an interface or the something like that in my code.
What do I need to know in order to expose a class's methods and properties for use in OLE Automation?
I am assuming since you used the phrase manifest, you are assembling this DLL using a .net development platform VS2003, VS2005 or VS2008 as compared to a VS 6.0
This link provides a detailed set of steps required to register a .NET assembly for use as COM component.
The one thing the article doesn't mention that I routinely do is create my own GUIDs. Use the Create GUID item in the Tools menu then insert them above the classes, interfaces, and enums you want exposed for COM.
[Guid("3838ADC1-E901-4003-BD0C-A889A7CF25A1")]
public interface IMyCOMClass {
void MyMethod();
}
[Guid("476BDEB6-B933-4ed5-8B86-7D9330A59356"),
ClassInterface(ClassInterfaceType.None)]
public class MyCOMClass : IMyCOMClass {
public void MyMethod() {
//implementation here
}
}
The second thing I do is use a separate interface for the COM portion that is implemented by the class. The reasoning for doing this has to do with the breakability of COM when the interface changes, think DLL Hell.
Hope this helps,
Bill.
(Assuming it's a .NET project)
Besides having to add the Guids to your interfaces and classes, you also need to mark them with the ComVisible attribute (unless you've marked the whole assembly with it). Also, you need to use the tlbexp.exe to export the metadata as a COM typelibrary for referencing in unmanaged clients.