Tenho um projeto do .NET Framework 4.5 e quero migrá-lo para o .NET Standard 2.0.
Quando tento abrir este projeto, uma janela aparece informando que o projeto está direcionado ao .NET Framework 4.5 e não é mais compatível. Também exige que eu atualize o destino para o .NET Framework 4.8 ou baixe o .NET Framework 4.5 diretamente do navegador. Caso contrário, não consigo carregar o projeto.
Mas não quero fazer nada disso.
Pesquisando na internet descobri que basta atualizar o .csproj, escolher "netstandard2.0" como TargetFramework e atualizar os pacotes com NuGet.
Então meu .csproj era mais ou menos assim:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{756DBCF8-3349-4CAE-B58C-47B7998BE3FF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Wke.Cms</RootNamespace>
<AssemblyName>Wke.Cms</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
...
More below
...
e simplesmente fiz esta pequena alteração abrindo o arquivo no meu explorador de arquivos:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{756DBCF8-3349-4CAE-B58C-47B7998BE3FF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Wke.Cms</RootNamespace>
<AssemblyName>Wke.Cms</AssemblyName>
<TargetFramework>netstandard2.0</TargetFramework>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
Alterado "TargetFrameworkVersion" para "TargetFramework" e colocado "netstandard2.0"
Agora posso carregar o projeto, mas se tento abrir as propriedades do projeto recebo o seguinte erro:
12/04/2024 10:42:18
Recoverable
System.ArgumentException: Expected 1 values for property Build::DefineConstants, but got 0. The property page may not be defined for all configurations.
Nombre del parámetro: values
en Microsoft.Requires.Argument(Boolean condition, String parameterName, ValidationInterpolatedStringHandler& message)
en Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.Property.Update(ImmutableArray`1 values)
en Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.Property..ctor(PropertyMetadata metadata, ImmutableArray`1 values, PropertyContext context, ImmutableHashSet`1 varyByDimensions)
en Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.PropertyContextFactoryBase.ToProperty(IUIPropertySnapshot property, Page page, Category category, Int32 order, PropertyContext propertyContext, IPropertyEditorRegistry propertyEditorRegistry)
en Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.<HandleDataAsync>g__CreateProperties|14_5(<>c__DisplayClass14_0& )
en Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.<HandleDataAsync>g__ProcessInitialData|14_1(<>c__DisplayClass14_0& )
Tentei pesquisar no Google e encontrei isso , mas não funcionou para mim.
O que estou perdendo aqui? Preciso fazer mais alterações? Qualquer ajuda é mais que bem-vinda.