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)
13429정성태10/27/20232923닷넷: 2152. Win32 Interop - C/C++ DLL로부터 이중 포인터 버퍼를 C#으로 받는 예제파일 다운로드1
13428정성태10/25/20232984닷넷: 2151. C# 12 - ref readonly 매개변수
13427정성태10/18/20233159닷넷: 2150. C# 12 - 정적 문맥에서 인스턴스 멤버에 대한 nameof 접근 허용(Allow nameof to always access instance members from static context)
13426정성태10/13/20233326스크립트: 59. 파이썬 - 비동기 호출 함수(run_until_complete, run_in_executor, create_task, run_in_threadpool)
13425정성태10/11/20233140닷넷: 2149. C# - PLinq의 Partitioner<T>를 이용한 사용자 정의 분할파일 다운로드1
13423정성태10/6/20233119스크립트: 58. 파이썬 - async/await 기본 사용법
13422정성태10/5/20233274닷넷: 2148. C# - async 유무에 따른 awaitable 메서드의 병렬 및 예외 처리
13421정성태10/4/20233319닷넷: 2147. C# - 비동기 메서드의 async 예약어 유무에 따른 차이
13420정성태9/26/20235476스크립트: 57. 파이썬 - UnboundLocalError: cannot access local variable '...' where it is not associated with a value
13419정성태9/25/20233148스크립트: 56. 파이썬 - RuntimeError: dictionary changed size during iteration
13418정성태9/25/20233845닷넷: 2146. C# - ConcurrentDictionary 자료 구조의 동기화 방식
13417정성태9/19/20233400닷넷: 2145. C# - 제네릭의 형식 매개변수에 속한 (매개변수를 가진) 생성자를 호출하는 방법
13416정성태9/19/20233186오류 유형: 877. redis-py - MISCONF Redis is configured to save RDB snapshots, ...
13415정성태9/18/20233679닷넷: 2144. C# 12 - 컬렉션 식(Collection Expressions)
13414정성태9/16/20233448디버깅 기술: 193. Windbg - ThreadStatic 필드 값을 조사하는 방법
13413정성태9/14/20233642닷넷: 2143. C# - 시스템 Time Zone 변경 시 이벤트 알림을 받는 방법
13412정성태9/14/20236924닷넷: 2142. C# 12 - 인라인 배열(Inline Arrays) [1]
13411정성태9/12/20233416Windows: 252. 권한 상승 전/후 따로 관리되는 공유 네트워크 드라이브 정보
13410정성태9/11/20234934닷넷: 2141. C# 12 - Interceptor (컴파일 시에 메서드 호출 재작성) [1]
13409정성태9/8/20233790닷넷: 2140. C# - Win32 API를 이용한 모니터 전원 끄기
13408정성태9/5/20233767Windows: 251. 임의로 만든 EXE 파일을 포함한 ZIP 파일의 압축을 해제할 때 Windows Defender에 의해 삭제되는 경우
13407정성태9/4/20233516닷넷: 2139. C# - ParallelEnumerable을 이용한 IEnumerable에 대한 병렬 처리
13406정성태9/4/20233478VS.NET IDE: 186. Visual Studio Community 버전의 라이선스
13405정성태9/3/20233921닷넷: 2138. C# - async 메서드 호출 원칙
13404정성태8/29/20233432오류 유형: 876. Windows - 키보드의 등호(=, Equals sign) 키가 눌리지 않는 경우
13403정성태8/21/20233266오류 유형: 875. The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...