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분
정성태

... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13222정성태1/20/20233932개발 환경 구성: 657. WSL - DockerDesktop.vhdx 파일 위치를 옮기는 방법
13221정성태1/19/20234164Linux: 57. C# - 리눅스 프로세스 메모리 정보파일 다운로드1
13220정성태1/19/20234314오류 유형: 837. NETSDK1045 The current .NET SDK does not support targeting .NET ...
13219정성태1/18/20233872Windows: 220. 네트워크의 인터넷 접속 가능 여부에 대한 판단 기준
13218정성태1/17/20233797VS.NET IDE: 178. Visual Studio 17.5 (Preview 2) - 포트 터널링을 이용한 웹 응용 프로그램의 외부 접근 허용
13217정성태1/13/20234391디버깅 기술: 185. windbg - 64비트 운영체제에서 작업 관리자로 뜬 32비트 프로세스의 덤프를 sos로 디버깅하는 방법
13216정성태1/12/20234655디버깅 기술: 184. windbg - 32비트 프로세스의 메모리 덤프인 경우 !peb 명령어로 나타나지 않는 환경 변수
13215정성태1/11/20236162Linux: 56. 리눅스 - /proc/pid/stat 정보를 이용해 프로세스의 CPU 사용량 구하는 방법 [1]
13214정성태1/10/20235732.NET Framework: 2087. .NET 6부터 SourceGenerator와 통합된 System.Text.Json [1]파일 다운로드1
13213정성태1/9/20235270오류 유형: 836. docker 이미지 빌드 시 "RUN apt install ..." 명령어가 실패하는 이유
13212정성태1/8/20235029기타: 85. 단정도/배정도 부동 소수점의 정밀도(Precision)에 따른 형변환 손실
13211정성태1/6/20235112웹: 42. (https가 아닌) http 다운로드를 막는 웹 브라우저
13210정성태1/5/20234132Windows: 219. 윈도우 x64의 경우 0x00000000`7ffe0000 아래의 주소는 왜 사용하지 않을까요?
13209정성태1/4/20234033Windows: 218. 왜 윈도우에서 가상 메모리 공간은 64KB 정렬이 된 걸까요?
13208정성태1/3/20233964.NET Framework: 2086. C# - Windows 운영체제의 2MB Large 페이지 크기 할당 방법파일 다운로드1
13207정성태12/26/20224270.NET Framework: 2085. C# - gpedit.msc의 "User Rights Assignment" 특권을 코드로 설정/해제하는 방법파일 다운로드1
13206정성태12/24/20224476.NET Framework: 2084. C# - GetTokenInformation으로 사용자 SID(Security identifiers) 구하는 방법 [3]파일 다운로드1
13205정성태12/24/20224872.NET Framework: 2083. C# - C++과의 연동을 위한 구조체의 fixed 배열 필드 사용 (2)파일 다운로드1
13204정성태12/22/20224152.NET Framework: 2082. C# - (LSA_UNICODE_STRING 예제로) CustomMarshaler 사용법파일 다운로드1
13203정성태12/22/20224313.NET Framework: 2081. C# Interop 예제 - (LSA_UNICODE_STRING 예제로) 구조체를 C++에 전달하는 방법파일 다운로드1
13202정성태12/21/20224705기타: 84. 직렬화로 설명하는 Little/Big Endian파일 다운로드1
13201정성태12/20/20225330오류 유형: 835. PyCharm 사용 시 C 드라이브 용량 부족
13200정성태12/19/20224204오류 유형: 834. 이벤트 로그 - SSL Certificate Settings created by an admin process for endpoint
13199정성태12/19/20224492개발 환경 구성: 656. Internal Network 유형의 스위치로 공유한 Hyper-V의 VM과 호스트가 통신이 안 되는 경우
13198정성태12/18/20224370.NET Framework: 2080. C# - Microsoft.XmlSerializer.Generator 처리 없이 XmlSerializer 생성자를 예외 없이 사용하고 싶다면?파일 다운로드1
13197정성태12/17/20224308.NET Framework: 2079. .NET Core/5+ 환경에서 XmlSerializer 사용 시 System.IO.FileNotFoundException 예외 발생하는 경우파일 다운로드1
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...