Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

기존 .NET Framework 프로젝트를 .NET Core/5+ 용으로 변환해 주는 upgrade-assistant, try-convert 도구 소개

재미있는 도구가 preview 상태를 거치고 있군요. ^^

Introducing the .NET Upgrade Assistant Preview
; https://devblogs.microsoft.com/dotnet/introducing-the-net-upgrade-assistant-preview/

실제로 현재 .NET 5+가 있다면 다음의 명령어로 간단하게 설치할 수 있습니다.

// A tool to assist developers in upgrading .NET Framework applications to .NET 6 and beyond
// https://github.com/dotnet/upgrade-assistant

dotnet tool install -g upgrade-assistant
dotnet tool install -g try-convert

테스트를 해볼까요? ^^ .NET 4.0 콘솔 프로젝트를 하나 만들고, 해당 csproj 파일 경로를 인자로 upgrade-assistant를 실행하면,

[0.2.227701 버전 미만]
c:\temp\ConsoleApp1\ConsoleApp1> upgrade-assistant ConsoleApp1.csproj

[tool update]
c:\temp> dotnet tool update -g upgrade-assistant

[0.2.227701 버전 이후]
c:\temp\ConsoleApp1\ConsoleApp1> upgrade-assistant upgrade ConsoleApp1.csproj

다음과 같은 step의 명령행 모드로 진입합니다.

[09:43:14 INF] MSBuild registered from C:\Program Files\dotnet\sdk\5.0.200\
[09:43:14 INF] Registered 1 extensions:
        Default extension
[09:43:16 INF] Initializing upgrade step Select an entrypoint
[09:43:16 INF] Setting entrypoint to only project in solution: C:\temp\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj
[09:43:16 INF] Initializing upgrade step Select project to upgrade
[09:43:16 INF] Setting only project in solution as the current project: C:\temp\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj
[09:43:16 INF] Initializing upgrade step Back up project

Upgrade Steps

Entrypoint: C:\temp\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj
Current Project: C:\temp\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj

1. [Next step] Back up project
2. Convert project file to SDK style
3. Update TFM
4. Update NuGet packages
5. Add template files
6. Update C# source
    a. Apply fix for UA0001: ASP.NET Core projects should not reference ASP.NET namespaces
    b. Apply fix for UA0002: HtmlString types should be replaced with Microsoft.AspNetCore.Html.HtmlString
    c. Apply fix for UA0003: ActionResult types should come from the Microsoft.AspNetCore.Mvc namespace
    d. Apply fix for UA0004: Filter types should be used from the Microsoft.AspNetCore.Mvc.Filters namespace
    e. Apply fix for UA0005: Do not use HttpContext.Current
    f. Apply fix for UA0006: HttpContext.DebuggerEnabled should be replaced with System.Diagnostics.Debugger.IsAttached
    g. Apply fix for UA0007: HtmlHelper should be replaced with IHtmlHelper
    h. Apply fix for UA0008: UrlHelper should be replaced with IUrlHelper
    i. Apply fix for UA0009: HelperResult should be replaced with Microsoft.AspNetCore.Mvc.Razor.HelperResult
    j. Apply fix for UA0010: [AllowHtmlAttrubute] should be removed
7. Move to next project

Choose a command:
   1. Apply next step (Back up project)
   2. Skip next step (Back up project)
   3. See more step details
   4. Configure logging
   5. Exit
>

위의 "Choose a command"에 따라 일반적인 프로젝트의 경우 "1"을 계속해서 입력하는 식으로 진행하면 "Back up project", "Convert project file to SDK style", "Update TFM", "Update NuGet packages", "Add template files", "Update C# source" 단계를 거치면서 마이그레이션 변환이 마무리됩니다.

그런데, 사실 실질적인 작업은 "Convert project file to SDK style"이고 그것은 try-convert 도구가 해주기 때문에 다른 단계들이 별로 필요가 없다면 곧바로 try-convert 도구를 솔루션 파일이 있는 디렉터리에서 실행해도 됩니다.

C:\temp\ConsoleApp1> try-convert
Conversion complete!

그럼 솔루션이 포함한 모든 프로젝트를 .NET Core 유형으로 변환해 줍니다. 아래는 기본적인 .NET 4.0 C# 콘솔 프로젝트가 .NET Core 유형으로 변환된 예제입니다.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <OutputType>Exe</OutputType>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
    <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
  </ItemGroup>
</Project>

간단하죠?! ^^




참고로, upgrade-assistant만 설치하고 try-convert 없이 실행하면 "2. Convert project file to SDK style" 단계에서 다음과 같은 오류 메시지와 함께 변환에 실패합니다.

[09:47:57 INF] Applying upgrade step Convert project file to SDK style
[09:47:57 INF] Converting project file format with try-convert
[09:47:57 ERR] Unexpected error applying step
System.ComponentModel.Win32Exception (2): The system cannot find the file specified.
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Microsoft.DotNet.UpgradeAssistant.ProcessRunner.RunProcessAsync(ProcessInfo args, CancellationToken token) in /_/src/common/Microsoft.DotNet.UpgradeAssistant.Abstractions/ProcessRunner.cs:line 53
   at Microsoft.DotNet.UpgradeAssistant.Steps.ProjectFormat.TryConvertProjectConverterStep.RunTryConvertAsync(IUpgradeContext context, IProject project, CancellationToken token) in /_/src/steps/Microsoft.DotNet.UpgradeAssistant.Steps.ProjectFormat/TryConvertProjectConverterStep.cs:line 64
   at Microsoft.DotNet.UpgradeAssistant.Steps.ProjectFormat.TryConvertProjectConverterStep.ApplyImplAsync(IUpgradeContext context, CancellationToken token) in /_/src/steps/Microsoft.DotNet.UpgradeAssistant.Steps.ProjectFormat/TryConvertProjectConverterStep.cs:line 53
   at Microsoft.DotNet.UpgradeAssistant.UpgradeStep.ApplyAsync(IUpgradeContext context, CancellationToken token) in /_/src/common/Microsoft.DotNet.UpgradeAssistant.Abstractions/UpgradeStep.cs:line 169
Command (Apply next step (Convert project file to SDK style)) did not succeed




백업된 프로젝트 폴더를 복원한 후 다시 빌드하는 경우 다음과 같은 오류 메시지가 발생할 수 있습니다.

Your project does not reference ".NETFramework,Version=v4.0" framework. Add a reference to ".NETFramework,Version=v4.0" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.


^^ 고민하지 마시고, /bin, /obj 폴더를 삭제 후 다시 빌드하면 됩니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 11/20/2022]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2021-11-08 11시11분
[항상 감사하게 생각하고 있습니다.] c:\temp\ConsoleApp1\ConsoleApp1> upgrade-assistant ConsoleApp1.csproj
=> c:\temp\ConsoleApp1\ConsoleApp1> upgrade-assistant upgrade ConsoleApp1.csproj

항상 감사합니다.
[guest]
2021-11-08 11시40분
의견 감사합니다. 제가 저 글을 쓸 때 "0.2.212405" 버전이었고 그때는 별도의 "upgrade" 인자를 요구하지 않았는데, (0.2.227701부터) 버전업이 되면서 동작이 바뀌었군요. ^^
정성태
2022-11-20 01시04분
You can find the latest docs and news about the ASP.NET Incremental Migration Tooling and System.Web Adapters on GitHub at

dotnet/systemweb-adapters
; https://github.com/dotnet/systemweb-adapters
정성태
2023-03-03 09시20분
정성태

1  2  [3]  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13551정성태2/12/20242016닷넷: 2213. ASP.NET/Core 웹 응용 프로그램 - 2차 스레드의 예외로 인한 비정상 종료
13550정성태2/11/20242107Windows: 256. C# - Server socket이 닫히면 Accept 시켰던 자식 소켓이 닫힐까요?
13549정성태2/3/20242478개발 환경 구성: 706. C# - 컨테이너에서 실행하기 위한 (소켓) 콘솔 프로젝트 구성
13548정성태2/1/20242308개발 환경 구성: 705. "Docker Desktop for Windows" - ASP.NET Core 응용 프로그램의 소켓 주소 바인딩(IPv4/IPv6 loopback, Any)
13547정성태1/31/20242056개발 환경 구성: 704. Visual Studio - .NET 8 프로젝트부터 dockerfile에 추가된 "USER app" 설정
13546정성태1/30/20241896Windows: 255. (디버거의 영향 등으로) 대상 프로세스가 멈추면 Socket KeepAlive로 연결이 끊길까요?
13545정성태1/30/20241828닷넷: 2212. ASP.NET Core - 우선순위에 따른 HTTP/HTTPS 호스트:포트 바인딩 방법
13544정성태1/30/20241846오류 유형: 894. Microsoft.Data.SqlClient - Could not load file or assembly 'System.Security.Permissions, ...'
13543정성태1/30/20241826Windows: 254. Windows - 기본 사용 중인 5357 포트 비활성화는 방법
13542정성태1/30/20241876오류 유형: 893. Visual Studio - Web Application을 실행하지 못하는 IISExpress - 두 번째 이야기
13541정성태1/29/20241922VS.NET IDE: 188. launchSettings.json의 useSSL 옵션
13540정성태1/29/20242051Linux: 69. 리눅스 - "Docker Desktop for Windows" Container 환경에서 IPv6 Loopback Address 바인딩 오류
13539정성태1/26/20242146개발 환경 구성: 703. Visual Studio - launchSettings.json을 이용한 HTTP/HTTPS 포트 바인딩
13538정성태1/25/20242214닷넷: 2211. C# - NonGC(FOH) 영역에 .NET 개체를 생성파일 다운로드1
13537정성태1/24/20242268닷넷: 2210. C# - Native 메모리에 .NET 개체를 생성파일 다운로드1
13536정성태1/23/20242374닷넷: 2209. .NET 8 - NonGC Heap / FOH (Frozen Object Heap) [1]
13535정성태1/22/20242206닷넷: 2208. C# - GCHandle 구조체의 메모리 분석
13534정성태1/21/20242039닷넷: 2207. C# - SQL Server DB를 bacpac으로 Export/Import파일 다운로드1
13533정성태1/18/20242238닷넷: 2206. C# - TCP KeepAlive의 서버 측 구현파일 다운로드1
13532정성태1/17/20242149닷넷: 2205. C# - SuperSimpleTcp 사용 시 주의할 점파일 다운로드1
13531정성태1/16/20242026닷넷: 2204. C# - TCP KeepAlive에 새로 추가된 Retry 옵션파일 다운로드1
13530정성태1/15/20242010닷넷: 2203. C# - Python과의 AES 암호화 연동파일 다운로드1
13529정성태1/15/20241894닷넷: 2202. C# - PublishAot의 glibc에 대한 정적 링킹하는 방법
13528정성태1/14/20242032Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/20241959오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/20242048닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
1  2  [3]  4  5  6  7  8  9  10  11  12  13  14  15  ...