Change from netcore 1.1 to netcore 2.2 - .net-core-2.0

I have this old project which is in netcore 1.1 and I'm trying to run this project in my new Dev environment which is has netcore above 2.0. As you can guess when I'm trying to debug this old project my command line starts glowing like a christmas tree with all the known errors like
It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '1.1.2' was not found.
- Check application dependencies and target a framework version installed at:
C:\Program Files\dotnet\
and
- The following versions are installed:
2.1.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.2.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
So my question is how can I change my project settings without installing netcore 1.1?
Also worth to mention is that I already know how to fix this problem when working in Visual Studio with a project solution(just changing the version in project properties will fix this problem) but this project is in Visual Studio Code and it has no solution file inside the project folder.
I have already changed some settings in .csproj but without any luck.
This is what I have changed in .csproj From:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug"
Version="1.1.1" />
</ItemGroup>
</Project>
to:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
</Project>

Delete /bin and /obj folders and import Microsoft.AspNetCore.App in your .csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Api.Analyzers" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
</Project>

Related

TableClientConfiguration not found in .net6 as i updated core from 3.1 to 6

I have to update a project in which i have to update project from netcore 3.1 to net6
it was using
Microsoft.Azure.Cosmos.Table
i have updated it to
Azure.Data.Tables
as per Microsoft suggestion
i have updated all other reference but now i am facing issue that
TableClientConfiguration
don't exist it .net 6
my project file is
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.6.1" />
<PackageReference Include="Azure.Storage.Queues" Version="12.12.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Core" Version="3.0.33" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Moq" Version="4.18.2" />
</ItemGroup>
</Project>
even this microsoft for this class dont have help of this
https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.table.tableclientconfiguration?view=azure-dotnet
any idea with what i need to update it
or do i need to change the implementation ?
The migration guide shows a sample where it is simply removed.
The main settings there were related to how the connection to CosmosDB was done (Preferred region, Consistency Level, ...).
_tableClient = storageAccount.CreateCloudTableClient(
new TableClientConfiguration {
CosmosExecutorConfiguration = new CosmosExecutorConfiguration {
CurrentRegion = config.ApplicationRegion } });
This is not available in the new SDK (yet):
https://github.com/Azure/azure-sdk-for-net/issues/28986
https://github.com/Azure/azure-sdk-for-net/issues/30943

Azure function v2, Core 3.1 Could not load file or assembly System.Memory, Version=4.2.0.0

I'm running locally an Azure function v2 on Core 3.1. Function connects reads events from an EventHub and write data to a Redis database.
While connecting function gets an error
System.Private.CoreLib: Exception while executing function:
One or more errors occurred. (Could not load file or assembly 'System.Memory, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.).
Pipelines.Sockets.Unofficial: Could not load file or assembly 'System.Memory, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.
Same Redis connection code works normally as expected outside the Azure function.
I have installed System.Memory nuget package v 4.5.3 into the project but it does not help.
There is no System.Memory version 4.2 listed in nuget for Core 3.1
function uses Startup
[assembly: FunctionsStartup(typeof(...))]
The project file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="4.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageReference Include="System.Memory" Version="4.5.3" />
<PackageReference Include="Utf8Json" Version="1.3.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Configuration\Configuration.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
What's wrong?
The problem was fixed by changing the Azure functions version to v3 in project .csproj file.
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
If the problem persists, verify that you are using the correct version of Azure Functions Core Tools (v3), it happened to me that I took version 2 from nodejs that is, I had version 2 installed in nodejs and version 3 in the folder From microsoft in the path they were both but I took the first one that was the nodejs one and it kept giving me the error until I delete the nodejs one, you can update it to version 3 in nodejs and I suppose it will work the same.
Can you try to add true to your .csproj file:
<PropertyGroup>
...
<UseNETCoreGenerator>true</UseNETCoreGenerator>
</PropertyGroup>

Version problem on Azure Functions v1 (using .Net461/.Net472) with NotificationHub v3.1.0

I would like to run Azure Function v1 with .Net461/.Net472 for testing NotificationHub package. However, there is exception when executing below code:
await _hub.CreateOrUpdateRegistrationAsync(registration);
Error is :
Exception while executing function: PushRegister. Microsoft.Azure.NotificationHubs: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=XXX' or one of its dependencies. The system cannot find the file specified.
I tried to downgrade to 10.0.3 then had error like
Microsoft.Azure.NotificationHubs: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0 ...
Below is the XXX.csproj file for reference:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AzureFunctionsVersion>v1</AzureFunctionsVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.3" />
<PackageReference Include="Microsoft.Azure.NotificationHubs" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="2.3.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\YYY\YYY.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Most of the Nuget libraries have the dependency on Newtonsoft package, even the Microsoft.NET.Sdk.Functions has a dependency on it but it is of older version.
You cannot use any other Nuget Packages that have a dependency on Newtonsoft.Json version which is higher than the function runtime dependent version.
When you try to install a NuGet which has the dependency on a higher version of Newtsonsoft package, you simply cannot install it. The only solution is to use an older version of that library that you need.
I have also written a blog on this and on github this is already an open issue
https://medium.com/#hharan618/common-issues-while-development-of-azure-functions-76b08299af58

Dotnet Core 1.1 Azure Deployment: No executable found matching command "dotnet-publish-iis"

I'm getting an issue with deploying via git to Azure. My app called Blogg keeps getting hung up when the PostCompile command runs after the app gets published to the server. That command is:
<Exec Command="dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" />
I was under the impression that the package reference for this command came from Microsoft.AspNetCore.Server.IISIntegration but even after adding versions 1.1.0-preview4-final and 1.1.2 (the latest), I'm still having troubles.
In case it's helpful, below are what's in my .csproj file:
`<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.sqlserver.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0-msbuild2-final" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild2-final" />
</ItemGroup>
<ItemGroup>
<None Include="wwwroot/*" CopyToPublishDirectory="Always" />
<None Include="Views/*" CopyToPublishDirectory="Always" />
<None Include="web.config" CopyToPublishDirectory="Always" />
</ItemGroup>
<Target Name="MyPostCompileTarget" AfterTargets="Publish">
<Exec Command="dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" />
</Target>
</Project>`
And the error I'm getting from the Azure log:
`Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
Restoring packages for D:\home\site\repository\Blogg.csproj...
D:\Program Files (x86)\dotnet\sdk\1.0.0-rc4-004771\NuGet.targets(97,5): warning : Dependency specified was Microsoft.AspNetCore.Server.IISIntegration (>= 1.1.0-preview4-final) but ended up with Microsoft.AspNetCore.Server.IISIntegration 1.1.0. [D:\home\site\repository\Blogg.csproj]
Installing Microsoft.AspNetCore.Http.Features 1.1.0.
Installing Microsoft.AspNetCore.Hosting.Server.Abstractions 1.1.0.
Installing Microsoft.Extensions.Configuration.Abstractions 1.1.0.
Installing Microsoft.AspNetCore.Http.Abstractions 1.1.0.
Installing Microsoft.AspNetCore.WebUtilities 1.1.0.
Installing Microsoft.Extensions.ObjectPool 1.1.0.
Installing Microsoft.Net.Http.Headers 1.1.0.
Installing Microsoft.AspNetCore.Http.Extensions 1.1.0.
Installing Microsoft.AspNetCore.Hosting.Abstractions 1.1.0.
Installing Microsoft.AspNetCore.Http 1.1.0.
Installing Microsoft.Extensions.Logging.Abstractions 1.1.0.
Installing Microsoft.Extensions.Options 1.1.0.
Installing Microsoft.AspNetCore.HttpOverrides 1.1.0.
Installing Microsoft.AspNetCore.Server.IISIntegration 1.1.0.
Writing lock file to disk. Path: D:\home\site\repository\obj\project.assets.json
Restore completed in 18.69 sec for D:\home\site\repository\Blogg.csproj.
Restoring packages for D:\home\site\repository\Blogg.csproj...
Restore completed in 14.38 sec for D:\home\site\repository\Blogg.csproj.
Restoring packages for D:\home\site\repository\Blogg.csproj...
Restore completed in 17.49 sec for D:\home\site\repository\Blogg.csproj.
NuGet Config files used:
D:\local\AppData\NuGet\NuGet.Config
Feeds used:
https://api.nuget.org/v3/index.json
Installed:
14 package(s) to D:\home\site\repository\Blogg.csproj
Microsoft (R) Build Engine version 15.1.545.13942
Copyright (C) Microsoft Corporation. All rights reserved.
Blogg -> D:\home\site\repository\bin\Release\netcoreapp1.0\Blogg.dll
No executable found matching command "dotnet-publish-iis"
D:\home\site\repository\Blogg.csproj(30,5): error MSB3073: The command "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" exited with code 1.
Failed exitCode=1, command=dotnet publish "D:\home\site\repository\Blogg.csproj" --output "D:\local\Temp\8d4ac97ca692979" --configuration Release
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\62.60524.2862\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"`
When using csproj files for ASP.NET Core web applications, you can safely remove this line:
<Exec Command="dotnet publish-iis …" />
For project.json based projects, this command performed actions that are now performed by default if your project uses the web sdk:
<Project Sdk="Microsoft.NET.Sdk.Web">
It looks like the migration correctly removed the tools reference to the dotnet-publish-iis tool but did not remove the corresponding invocation. You could file an issue at the dotnet migrate tool's GitHub repository with your original project.json file.

Deploying a netcoreapp1.1 to Azure

I have netcoreapp1.1 that I am trying to publish to Azure with WebDeploy. I am able to do dotnet publish and deploy the contents to Azure, but the site just says "You do not have permission to view this directory or page.", which suggests the app is not running.
My previous apps have used net461 as target framework and I have noticed that publishing these (with dotnet publish) have caused a web.config file to be created, which explains how IIS is able to run it, but this does not happen when the target framework is netcoreapp1.1.
The command I have been using to publish is this:
dotnet publish --configuration Release --runtime win7-x64 --output .deploy
Here is my project file:
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
</PropertyGroup>
<ItemGroup>
<Compile Include="Controllers/*.fs" />
<Compile Include="Startup.fs" />
<Compile Include="Program.fs" />
<None Remove="**/*.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>
</Project>
How am I meant to run a netcoreapp1.1 on Azure? Does it have to be self contained or is it possible to have the Azure App Service run it from dlls?
Edit:
Manually copying a web.config into my publish directory I am able to get the app to run. How can I make dotnet publish create it automatically?
Also, I am still curious about my previous questions.
Add info into you csproj file that you need to copy web.config, like this:
<ItemGroup>
<Content Update="web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>

Resources