보통 간단한 윈도우 툴 만들 때는, winform을 애용한다 (디자인 너무 편해요)

 

이번에 net5로 갈아타면서 winform 디자인하는 데,

기존 net framework에 비해 느린 게 체감이 됨

 

"와 너무 느리다"까지는 아니지만, 1~2초 정도 딜레이가 있는 듯 함

약간 신경 쓰이는 정도... 특히 properties 쪽이 갱신되는 경우가 많음

 

어차피 간단한 툴 만드는거라 크게 문제는 없지만

net6에서는 개선이되면 참 좋겄습니다. 마소님

 

주저리...

그러고보니 이거 쓸 시간에, 속도 올리는 법이나 찾아볼껄

net framework 프로젝트로 디자인만 하고, net5에 복붙해서 사용해도 잘 되는 거 같긴하네..

 

'c#' 카테고리의 다른 글

net5 publishSingleFile 옵션 사용 시 난독화 방법  (0) 2021.08.11

 

4.6.x까지 잘 쓰던 confuserEx가 net5 지원을 안 해서 알아봄

1. 빌드하고

2. obfuscar 돌리고

3. publish 전 난독화 파일로 교체하는 형태임

 

obfuscar global 설치

# dotnet tool install --global Obfuscar.GlobalTool --version 2.2.31

 

VS 2019 설정

Project\Properties\PublishProfiles\FolderProfile.pubxml:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>..\publish\</PublishDir> <!--Optional for custom publish folder-->
    <PublishProtocol>FileSystem</PublishProtocol>
    <TargetFramework>net5.0-windows</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>false</SelfContained>
    <PublishSingleFile>True</PublishSingleFile>
    <PublishReadyToRun>False</PublishReadyToRun>
  </PropertyGroup>
</Project>

 

obfuscar.xml:

<?xml version="1.0" encoding="utf-8" ?>
<Obfuscator>
  <Var name="InPath" value=".\obj\Release\net5.0-windows\win-x64" />
  <Var name="OutPath" value=".\obj\Release\net5.0-windows\win-x64\Obfuscated" />
  
  <!--To solves "Unable to resolve dependency:  PresentationFramework" for WPF project.-->
  <AssemblySearchPath path="C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.8" />
  <!--To solves something what your project depdends like "Unable to resolve dependency: ...".-->
  <AssemblySearchPath path=".\bin\Release\net5.0-windows" />

  <Module file="$(InPath)\YourProjectOutput.dll" />
</Obfuscator>

 

Project.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  ...

  <!--Append these at the end of your .csproj file.-->
  <Target Name="Obfuscation" AfterTargets="AfterCompile" Condition="'$(PublishProtocol)'!=''">
    <Message Text="Obfuscating" Importance="high" /><!--Optional to log a message.-->    
    <Exec Command="obfuscar.console.exe obfuscar.xml" /><!--Assuming you have installed Obfuscar.GlobalTool(https://www.nuget.org/packages/Obfuscar.GlobalTool). -->
    <Exec Command="COPY $(ProjectDir)$(IntermediateOutputPath)Obfuscated\$(TargetFileName) $(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
  </Target>
</Project>

 

CLI 로 하려면

publish 할 때 --no-build 옵션이 중요함

# obfuscar.console.exe obfuscar.xml
# dotnet publish -c Release -r win-x64 -p:PublishSingleFile=true --self-contained false --no-build

 

참고

publish 할 때, dll 파일 어디선가 사용 중 이면 오류 뜨니 주의하자

(ILSPY로 결과물 확인하다가 오류 떠서 괜히 시간 버림 ㅠㅠ)

 

링크

https://www.nuget.org/packages/Obfuscar.GlobalTool

https://github.com/obfuscar/obfuscar

https://github.com/obfuscar/obfuscar/issues/314)

'c#' 카테고리의 다른 글

net5 winform 디자인 느려요... 너무까지는 아니고...  (0) 2021.08.12

+ Recent posts