Azure function with .net core 2 class library - c#

Since there is still no support for Webjobs in ASP.Net Core, i am going to use Azure functions instead.
I have 2 class libraries that are build with on .net core 2. i can reference them to my Azure function project without any issue but when i try to publish i get this error.
This is the reference from the Azure function to my lib
Any idea on how i can make this work? without changing my class lib?

Azure Functions doesn't currently support .Net Core 2 (more specifically, .Net Standard 2), however, it seems like the team is actively working on getting this support out...see here: Port runtime to .NET Core
Runtime will be ported to target Netstandard 2.0.
Depending on the functionality of your libraries, you may see if its possible to target instead Netstandard 1.3 which they do currently support
This issue will track the .NET Core port activities for porting the runtime to .NET core. Note that netstandard 1.3 assemblies can be used on Azure Functions and this is fully supported.
Update: added clarity based on #derape comments

.NET Core 2.0 is now supported by Azure Functions.
https://blogs.msdn.microsoft.com/appserviceteam/2017/09/25/develop-azure-functions-on-any-platform/

Since there is still no support for Webjobs in ASP.Net Core
My understanding is that the VS tooling is not ready yet, so you cannot have a project template targeted at that, or some easy Publish as webjobs menu item.
But as far as I got reading through blog posts, you can create a .NET Core console application, add some .cmd file to project root with content like:
REM run.cms - Webjob entry point
#echo off
dotnet MyNetCoreConsoleApplication.dll
include that in the set of published files (with project.json "publishOptions": { "include": [...] } and finally make the webjob point to that cmd script. See for example here, or search for azure webjobs dotnet core.

Related

Published version WPF .NET Core

I am looking to use code similar to the below, but in a .NET Core WPF C# application. This is what I previously used.
public static string GetVersion()
{
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
Version myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
return $"Version {myVersion}";
}
return "Version not deployed";
}
Is there an equivalent in .NET Core?
There is a closed issue around this issue and ClickOnce deployment.
ApplicationDeployment class is not available - that class is implemented in System.Deployment assembly that is not part of .NET Core 3.1 or .NET 5.
We will have a way to expose some of the properties that the class enables, i.e. URL parameters and update status. But, that work could not be completed for .NET 5 release. We will enable it in one of .NET 6 previews. Here are the tracking issues: #27 and #53
Use of ApplicationDeployment class in your deployed ClickOnce application is not possible, but main ClickOnce experience is available. It includes: creating ClickOnce deployment (manifests), publishing the application, creating and publishing updates. Your application will get automatic update check (and update, if user accepts it) - this part is handled by ClickOnce runtime and the new Launcher tool that becomes the entry point of ClickOnce deployment for .NET Core 3.1 and .NET 5 applications.
Consequently, as for now there does not seem to be a way to do this in .NET Core directly.
You should be able to get the assembly version using System.Reflection.Assembly.GetExecutingAssembly().GetName().Version, as shown in
Reading Assembly version information of WPF application
For more click-once capabilities not ported to .net core3.1/5/6, look here https://github.com/derskythe/WpfSettings
There has been some progress on this in .NET. According to a comment by a Microsoft employee you can now detect these values via environment variables as is done in mage.exe. For example something like this:
bool.TryParse(Environment.GetEnvironmentVariable("ClickOnce_IsNetworkDeployed"), out bool isNetworkDeployed);
Version.TryParse(Environment.GetEnvironmentVariable("ClickOnce_CurrentVersion"), out Version currentVersion);
Most of the discussion on that GitHub issue is about .NET 7. On the other hand, some comments suggest this code has its own independent release schedule. I don't know enough to say if/when it will be available in Core.

Should I use "--self-contained true" when publishing a .NET Core 3.1 Lambda to AWS?

Simple question as the title implies... I know with a .NET 5.0 package, I would have to provide it as a custom runtime and package it as self contained. But with .NET Core 3.1 which is natively supported by AWS, are there any pros/cons to using the flag "--self-contained true"?
As far as I'm aware, cold starts can be affected by larger package bundles (such as the ones that include the runtime). Have a look at Cold starts with .NET Core 3.0 in this article.
So I wouldn't make it self contained unless you have a good reason to do it (i.e., having to use .NET 5).

Why does a dotnet Core App with a reference to a classic .Net project works and compiles [duplicate]

I'd really like to start using .NET Core and slowly migrate applications and libraries to it. However, I can't realistically upgrade my entire code base to use .NET Core and then go through the process of testing and deploying a plethora of applications in production.
As an example, if I create a new .NET Core application and try to reference one of my .NET Framework projects I get the following:
The following projects are not supported as references: -
Foobar.NetFramework has target frameworks that are incompatible with
targets in current project Foobar.NetCore.
Foobar.NetCore: .NETCoreApp,Version=v1.0
Foobar.NetFramework: .NETFramework,Version=v4.5
Is it possible to create a new .NET Core application and reference my existing .NET Framework libraries? If so, what's the process for doing that? I've spent hours going through Microsoft's documentation and searching their issues on GitHub, but I can't find anything official on how to achieve this or what their long-term vision is for this process.
Old question, but with the release of .NetStandard 2.0 and .netcore 2.0 and vs2017.3, the game has changed.
You can use the Full .NET Framework (TFM) with .NetCore 2.0, but how?
In Visual Studio 2017.3, you can reference the Full .NET Framework (any version) directly from within a .NetCore2 project.
You can build the .NetStandard2 class library and reference your TFM. Then reference your .NetStandard2 library from your .NetCore2 project.
For example, referencing json.net net45 from .NetStandard2.
Browse to the folder and select version net45 (not netstandard1.3)
See the dependency in the image below, no yellow warning as you see.
Even if a Nuget library is not ready to be ported to .Netstandard 2, you can use any API in the library that is compliant to net461.
Quoting for the .NET Core 2/Standard 2.0 announcement with links:
.NET Core 2.0 is able to freely reference libraries that have been built for .NET Framework up to version 4.6.1
However, some libraries may fail at run time if they try to use API methods that aren't available on .NET Core
Reference: .NET Core App target .NET framework 4.5.2 on Linux
A need to use third-party .NET libraries or NuGet packages not available for .NET Core
So only in cases where the libraries or NuGet packages use technologies that aren't available in .NET Standard/.NET Core, you need to use the .NET Framework.
Reference: Choosing between .NET Core and .NET Framework for server apps
You can now reference .NET Framework libraries from .NET Standard libraries using Visual Studio 2017 15.3. This feature helps you migrate .NET Framework code to .NET Standard or .NET Core over time (start with binaries and then move to source). It is also useful in the case that the source code is no longer accessible or is lost for a .NET Framework library, enabling it to be still be used in new scenarios.
Reference: Announcing .NET Core 2.0
Yes, we are currently attempting the same thing. The trick is to make sure that you are supporting the same .NET frameworks. Inside your project.json file, make sure the framework matches the framework of the project you wish to include. For example:
"frameworks": {
"net46": { --This line here <<<<
"dependencies": {
"DomainModel": {
"target": "project"
},
"Models": {
"target": "project"
}
}
}
},
FYI: You might need to change the framework of your .NET Core or your older projects to achieve this. .NET Core can be changed just by editing the project.json file as seen above. You can so the same in .NET projects by right clicking the project and opening properties. Change the framework level there.
Once you have matched the two project frameworks then you should be able to include them. Good Luck!
We delayed migrations as long as could as it seemed daunting as first. But we got an insistent client who wanted to migrate ASAP.
So we migrated their Fintech Web App developed on .NET Framework 4.8 Web Forms to .NET 6 Razor Page. Our team scoured though hundreds of online resources & spoke to Microsoft Tech Support before we started the project. Hope the high-level walkthrough of our journey help you plan your migrations.
Our .NET Framework Website consisted of 1 .NET Web Forms project and 12 Class Libraries.
Here is how we did it.
Refactored the .NET Framework 4.8 Web Forms code
We ensured that the Web Forms code behind did not have a single line of service or business logic code. When we did find some business logic code in the web forms code behind, we refactored it, by moving it to the class libraries.
Created new .NET Standard projects
We created a new .Standard 2.0 Class library project for every .NET Framework 4.8 Class Library. If the original project was called "FintechProjectName.StockMarketClient", we named the .NET standard project "FintechProjectName.StockMarketClient.Standard".
Copied all files from .NET framework to .NET standard
We copied all the class files from .NET framework to .NET standard projects. We then removed all the .NET framework class libraries from the solution and added references to the new class libraries. All projects compiled on the 1st try itself and all our test cases too passed with minor changes.
Create new .NET 6 Web App Project
We created a new .NET 6 Web App Project. We had to entirely redo the front-end as there is no direct path for migrating Web Forms to Razor Pages. This was the only project which took us about 1 month to migrate.
Reference .NET standard class libraries in the new .NET 6 website
We copied all the .NET Standard libraries to this new solution containing the Razor Pages web site. Added the references and got it to work.
Move from .NET Standard to .NET 6 class libraries
Once the new website was up and running, with all test cases passed, we did the last step in the process which was the simplest. Created .NET 6 class library projects for each of the .NET standard libraries and named the projects appropriately. Copied all class files from .NET standard projects to their corresponding .NET 6 projects. Then we removed the .NET Standard libraries and added references to the new class libraries.
Overall project timelines were about a month and a half, most of it spend on Razor Pages implementation using the same html design.
Note:
If you are using any 3rd party library which does not have a .NET standard or .NET 5 version, then you are out of luck. You will need to find a replacement nuget package and recode your application to use this new library.
In my case with .net6 referencing framework 4.8 library ( both winforms), the trick seems to be to add the reference to the framework dll as a shared reference.

Visual Studio - Cannot start ASP.NET Core project

Last few months I create console applications with .NET framework and C#.
Now I want to create ASP.NET Core MVC projects, but I cannot choose any .NET Core template.
If I click "Console App (.NET Core)" or "ASP.NET Core Web Application" or any other .NET Core template, I can see this error message:
So, the problem occurs if I choose "Core", other templates work fine.
I have already tried to find a solution on Google.
What could be the problem? I reinstalled VS few times but did not help.
.NET Core does not support COM. COM is a Windows-only thing, and everything in Core is cross-platform. You must run on the full framework if you need to utilize a COM library.
That said, Microsoft has recently release a preview NuGet with some Windows compatibility APIs. This may allow you to utilize COM; I haven't tried it. However, the stated purpose of the NuGet is to make it easier to migrate existing .NET Framework applications to .NET Standard/.NET Core, so it's not considered something you would continue to utilize long-term. Rather, the idea is that you would actively work to migrate code that is not compatible to equivalent .NET Standard/.NET Core APIs, and then eventually remove the package entirely. As a result, it's probably not a good idea to go this route, even if it does enable you to use the COM library, simply because you're not likely to be able to stop at some point in the future.
Long and short, just run on the full framework.

Azure Function in dotnet core

I'm trying to port my C# code over to dotnet core so that my Function would be able to run cross-platform (if it had to).
I'm currently struggling to find Microsoft.Azure.WebJobs.Host for core. Has that not been implemented yet? Which currently means there's no logging.
Are there other things that currently don't work in core?
If you simply reference Microsoft.NET.Sdk.Functions NuGet version 1.0.6, you will get Microsoft.Azure.WebJobs.Host with it, including the logger. It is compatible to .NET Core.
See a working example in this repo.

Categories