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.
Related
Ive build out a service as a console application, it exists across 2 different projects in the solution, both are in .NET framework. I am wanting to add in an api level to this and am wondering if I should continue to use .NET framework for the web application project, or if I can use .NET Core without messing anything up.
It all depends on the APIs you use in your application. If you only use APIs included in .NET Standard then no problem to use them in an application under .NET 6. Otherwise I join Kirk Woll to migrate your code under .NET 6 especially since the unification of the platform. I think it will remain only .NET 6 aka .NET core in the future.
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.
I'm trying to migrate my app from .NET Core 2.1 to .NET Core 3.0. I've seen Microsoft document regarding this kind of migration, but I've also seen 2 or 3 tutorials which are way shorter than it and are enough to migrate the app.
I started with changing the <TargetFramework> from netcoreapp2.1 to netcoreapp3.0. As expected, it caused a few issues regarding all the packages, but I resolved it by upgrading them or changing deprecated methods to another.
Now the things are getting weird. I tried to run the application, but got following error:
Could not load type 'Microsoft.AspNetCore.Mvc.MvcJsonOptions' from assembly 'Microsoft.AspNetCore.Mvc.Formatters.Json, Version=3.0.0.0
OK, happens, not the first time I encounter some issue during this migration and probably not last. According to this topic found on Stack, it is because MvcJsonOptions has been removed in .NET Core 3.0. I tried to search for it in my application, but couldn't find any code. Guess it's some internal stuff then. Anyway, most upvoted solution was to update Swashbuckle to version 5.0, so I did. And here comes my troubles:
When I try to run the application, I get "Failed to bind to address http://localhost:5000". This is strange, because few minutes before I've just run this app but in .NET Core 2.1 and it worked perfectly fine. I have checked ports using netstat and port 5000 isn't used by anything. I'm using IIS Express.
When I change the host, I simply cannot run the application. It just loads forever. I've set some breakpoints, but everything looks fine - it just goes through all the code in the Startup.cs, but then it loads infinitely. What seems to be worse, I tried to change the port on another copy of my app, before migrating it to .NET Core 3.0 and it works perfectly fine. Just changed the numbers in appsettings.json and launchsettings.json and it works.
So in summary, my application fails to bind to my standard address after migrating it to .NET Core 3.0 and when I change it, something very strange is happening and it loads infinitely. Any ideas?
MvcJsonOptions has been removed in .net core 3.0. Try installing Newtonsoft.Json NuGet Package and build your 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.
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.