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)
13574정성태3/6/20241552닷넷: 2226. C# - "Docker Desktop for Windows" Container 환경에서의 IPv6 DualMode 소켓
13573정성태3/5/20241561닷넷: 2225. Windbg - dumasync로 분석하는 async/await 호출
13572정성태3/4/20241635닷넷: 2224. C# - WPF의 Dispatcher Queue로 알아보는 await 호출의 hang 현상파일 다운로드1
13571정성태3/1/20241598닷넷: 2223. C# - await 호출과 WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13570정성태2/29/20241623닷넷: 2222. C# - WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13569정성태2/28/20241537닷넷: 2221. C# - LoadContext, LoadFromContext 그리고 GAC파일 다운로드1
13568정성태2/27/20241602닷넷: 2220. C# - .NET Framework 프로세스의 LoaderOptimization 설정을 확인하는 방법파일 다운로드1
13567정성태2/27/20241613오류 유형: 898. .NET Framework 3.5 이하에서 mscoree.tlb 참조 시 System.BadImageFormatException파일 다운로드1
13566정성태2/27/20241626오류 유형: 897. Windows 7 SDK 설치 시 ".NET Development" 옵션이 비활성으로 선택이 안 되는 경우
13565정성태2/23/20241464닷넷: 2219. .NET CLR2 보안 모델에서의 개별 System.Security.Permissions 제어
13564정성태2/22/20241608Windows: 259. Hyper-V Generation 1 유형의 VM을 Generation 2 유형으로 바꾸는 방법
13563정성태2/21/20241625디버깅 기술: 196. windbg - async/await 비동기인 경우 메모리 덤프 분석의 어려움
13562정성태2/21/20241628오류 유형: 896. ASP.NET - .NET Framework 기본 예제에서 System.Web에 대한 System.IO.FileNotFoundException 예외 발생
13561정성태2/20/20241739닷넷: 2218. C# - (예를 들어, Socket) 비동기 I/O에 대한 await 호출 시 CancellationToken을 이용한 취소파일 다운로드1
13560정성태2/19/20241743디버깅 기술: 195. windbg 분석 사례 - Semaphore 잠금으로 인한 Hang 현상 (닷넷)
13559정성태2/19/20242620오류 유형: 895. ASP.NET - System.Security.SecurityException: 'Requested registry access is not allowed.'
13558정성태2/18/20241814닷넷: 2217. C# - 최댓값이 1인 SemaphoreSlim 보다 Mutex 또는 lock(obj)를 선택하는 것이 나은 이유
13557정성태2/18/20241569Windows: 258. Task Scheduler의 Author 속성 값을 변경하는 방법
13556정성태2/17/20241634Windows: 257. Windows - Symbolic (hard/soft) Link 및 Junction 차이점
13555정성태2/15/20241946닷넷: 2216. C# - SemaphoreSlim 사용 시 주의점
13554정성태2/15/20241706VS.NET IDE: 189. Visual Studio - 닷넷 소스코드 디컴파일 찾기가 안 될 때
13553정성태2/14/20241728닷넷: 2215. windbg - thin/fat lock 없이 동작하는 Monitor.Wait + Pulse
13552정성태2/13/20241682닷넷: 2214. windbg - Monitor.Enter의 thin lock과 fat lock
13551정성태2/12/20242011닷넷: 2213. ASP.NET/Core 웹 응용 프로그램 - 2차 스레드의 예외로 인한 비정상 종료
13550정성태2/11/20242101Windows: 256. C# - Server socket이 닫히면 Accept 시켰던 자식 소켓이 닫힐까요?
13549정성태2/3/20242473개발 환경 구성: 706. C# - 컨테이너에서 실행하기 위한 (소켓) 콘솔 프로젝트 구성
1  [2]  3  4  5  6  7  8  9  10  11  12  13  14  15  ...