Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)
(시리즈 글이 6개 있습니다.)
개발 환경 구성: 300. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법
; https://www.sysnet.pe.kr/2/0/11052

.NET Framework: 828. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/11884

개발 환경 구성: 466. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 세 번째 이야기
; https://www.sysnet.pe.kr/2/0/12118

.NET Framework: 878. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 네 번째 이야기(IL 코드로 직접 구현)
; https://www.sysnet.pe.kr/2/0/12120

.NET Framework: 880. C# - PE 파일로부터 IMAGE_COR20_HEADER 및 VTableFixups 테이블 분석
; https://www.sysnet.pe.kr/2/0/12126

.NET Framework: 881. C# DLL에서 제공하는 Win32 export 함수의 내부 동작 방식(VT Fix up Table)
; https://www.sysnet.pe.kr/2/0/12127




C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 세 번째 이야기

지난 글들에 이어,

C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법
; https://www.sysnet.pe.kr/2/0/11052

C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/11884

근래 다시 한번 dllexport를 테스트할 일이 있어 "C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법" 글에서 소개한 UnmanagedExports를 사용해 봤는데 아쉽게도 동작하지 않았습니다.

검색해 보니까, NuGet으로 받은 것은 업데이트가 끊겼고 대신 github를 통해 제공하는 것을 사용해야 합니다.

UnmanagedExports - v1.6.5
; https://github.com/3F/DllExport/releases
; https://github.com/3F/DllExport/releases/download/v1.6.5/offline.DllExport_v1.6.5.4044_4db7142.zip

그리고 사용법이 쪼끔 복잡해졌습니다. 예전에는 그냥 NuGet으로 받아 빌드만 하면 되었는데 이제는 다음의 글에 따라,

3F / DllExport - Quick start
; https://github.com/3F/DllExport/wiki/Quick-start

사전 configuration을 수행해야 합니다. 사실 "쪼끔" 복잡은 해졌지만 그래도 간단한 편인데 일단 솔루션/프로젝트를 구성한 다음 솔루션(sln) 파일이 있는 폴더에 "offline.DllExport_v1.6.5.4044_4db7142.zip" 파일의 압축을 풀어 놓고 시작하게 됩니다. 즉, 다음과 같은 식으로 폴더 구성이 되어야 합니다.

cs_export_native_0.png

그런 다음 "DllExport.bat -action Configure"라고 명령어를 수행합니다.

c:\temp\ConsoleApp1> DllExport.bat -action Configure
...[생략]...

"DllExport.bat" 실행의 기본 인자 구성이 "-action Configure"이므로 특별한 인자 없이 실행해도 됩니다. 그럼, 실행 중에 다음과 같이 솔루션 파일을 선택하는 대화창이 뜨고,

cs_export_native_1.png

그 솔루션 파일 내의 (export 함수를 구현할) 프로젝트를 선택한 후 Apply 버튼을 누르면 해당 프로젝트 파일(csproj) 내에 다음과 같은 식의 옵션들과 함께,

<PropertyGroup>
    <DllExportIdent>F5B3AFFA-7FAC-4B75-8AE3-A1B9F7AC2137</DllExportIdent>
    <DllExportMetaLibName>DllExport.dll</DllExportMetaLibName>
    <DllExportNamespace>ClassLibrary1</DllExportNamespace>
    <DllExportDDNSCecil>true</DllExportDDNSCecil>
    <DllExportSkipOnAnyCpu>false</DllExportSkipOnAnyCpu>
    <DllExportPlatform>Auto</DllExportPlatform>
    <DllExportOrdinalsBase>1</DllExportOrdinalsBase>
    <DllExportGenExpLib>false</DllExportGenExpLib>
    <DllExportOurILAsm>false</DllExportOurILAsm>
    <DllExportLeaveIntermediateFiles>false</DllExportLeaveIntermediateFiles>
    <DllExportTimeout>30000</DllExportTimeout>
    <DllExportPeCheck>2</DllExportPeCheck>
</PropertyGroup>

빌드 시에만 잠깐 사용될 dll 참조도 추가되고,

<Reference Include="DllExport, PublicKeyToken=8337224c9ad9e356">
    <HintPath>$(SolutionDir)\packages.offline\DllExport\gcache\metalib\$(DllExportNamespace)\$(DllExportMetaLibName)</HintPath>
    <Private>False</Private>
    <SpecificVersion>False</SpecificVersion>
</Reference>

msbuild가 사용할 빌드 단계도 추가됩니다.

<ImportGroup Label=".NET DllExport">
    <Import Project="$(SolutionDir)packages.offline\DllExport\tools\net.r_eg.DllExport.targets" Condition="Exists($([MSBuild]::Escape('$(SolutionDir)packages.offline\DllExport\tools\net.r_eg.DllExport.targets')))" Label="8337224c9ad9e356" />
</ImportGroup>

<Target Name="DllExportRestorePkg" BeforeTargets="PrepareForBuild">
    <Error Condition="!Exists('$(SolutionDir)DllExport.bat')" Text="DllExport.bat is not found. Path: '$(SolutionDir)' - https://github.com/3F/DllExport" />
    <Exec Condition="('$(DllExportModImported)' != 'true' Or !Exists('$(SolutionDir)packages.offline\DllExport\tools\net.r_eg.DllExport.targets')) And Exists('$(SolutionDir)DllExport.bat')" Command="DllExport.bat -packages packages.offline -dxp-version actual  -action Restore" WorkingDirectory="$(SolutionDir)" />
</Target>

<Target Name="DllExportRPkgDynamicImport" BeforeTargets="PostBuildEvent" DependsOnTargets="GetFrameworkPaths" Condition="'$(DllExportModImported)' != 'true' And '$(DllExportRPkgDyn)' != 'false'">
    <MSBuild BuildInParallel="true" UseResultsCache="true" Projects="$(MSBuildProjectFullPath)" Properties="DllExportRPkgDyn=true" Targets="Build" />
</Target>

따라서, 일단 저렇게 설정이 된 이후에는 그냥 빌드만 하면 export 함수를 가진 DLL이 생성됩니다. 게다가 AnyCPU 빌드 구성이어도 자동으로 x86 및 x64 바이너리를 한꺼번에 만듭니다.




NuGet을 사용하지 않기 때문에 업그레이드가 불편할 수 있지만, 이 부분에 대해서도 DllExport.bat 파일로 다음과 같이 해결할 수 있습니다.

DllExport -action Upgrade {version}

참고로, 다음은 offline.DllExport_v1.6.5.4044_4db7142.zip 압축 파일의 파일 및 디렉터리 구성입니다.

./
│   DllExport.bat
│   Readme.txt
│
└───packages.offline
    └───DllExport
        │   3rd-party.txt
        │   build_info.txt
        │   changelog.txt
        │   DllExport.bat
        │   DllExport.nuspec
        │   hMSBuild.bat
        │   License.txt
        │   Readme.md
        │
        ├───build
        │   └───net20
        │           DllExport.targets
        │
        ├───lib
        │   └───net20
        │           _._
        │
        └───tools
            │   build.targets
            │   Conari.dll
            │   Conari.pdb
            │   Conari.xml
            │   gnt.bat
            │   hMSBuild.bat
            │   Microsoft.Build.dll
            │   Microsoft.Build.Framework.dll
            │   Microsoft.Build.Utilities.v4.0.dll
            │   Mono.Cecil.dll
            │   MvsSln.dll
            │   MvsSln.pdb
            │   MvsSln.xml
            │   net.r_eg.DllExport.targets
            │   net.r_eg.DllExport.Wizard.dll
            │   net.r_eg.DllExport.Wizard.pdb
            │   net.r_eg.DllExport.Wizard.targets
            │   NSBin.dll
            │   NSBin.pdb
            │   PeViewer.exe
            │   PeViewer.pdb
            │   RGiesecke.DllExport.dll
            │   RGiesecke.DllExport.MSBuild.dll
            │   RGiesecke.DllExport.MSBuild.pdb
            │   RGiesecke.DllExport.pdb
            │
            ├───coreclr
            │       changelog.txt
            │       coreclr.dll
            │       ilasm.exe
            │       ildasm.exe
            │       ildasmrc.dll
            │       LICENSE.TXT
            │       mscordaccore.dll
            │       mscordbi.dll
            │       PATENTS.TXT
            │       README.md
            │       _Version.txt
            │
            └───raw
                └───lib
                    └───net20
                            DllExport.dll
                            DllExport.xml




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 1/17/2020]

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

비밀번호

댓글 작성자
 



2020-07-01 04시28분
정성태

... 106  107  108  109  110  111  112  113  114  115  116  117  [118]  119  120  ...
NoWriterDateCnt.TitleFile(s)
10975정성태5/20/201623221Math: 17. C# - 복소수 타입의 승수를 지원하는 Power 메서드파일 다운로드1
10974정성태5/20/201623749.NET Framework: 588. C# - OxyPlot 라이브러리로 복소수 표현파일 다운로드1
10973정성태5/20/201628765.NET Framework: 587. C# Plotting 라이브러리 OxyPlot [3]파일 다운로드1
10972정성태5/19/201627879Math: 16. C# - 갈루아 필드 GF(2) 연산 [3]파일 다운로드1
10971정성태5/19/201620683오류 유형: 334. Visual Studio - 빌드 시 경고 warning MSB3884: Could not find rule set file "...". [2]
10970정성태5/19/201625033오류 유형: 333. OxyPlot 라이브러리의 컨트롤을 Toolbox에 등록 시 오류 [2]
10969정성태5/18/201624335.NET Framework: 586. C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (3) - "Open with" 목록에 등록파일 다운로드1
10968정성태5/18/201619351오류 유형: 332. Visual Studio - 단위 테스트 생성 시 "Design time expression evaluation" 오류 메시지
10967정성태5/12/201624421.NET Framework: 585. C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (2) - 웹 브라우저가 다운로드 후 자동 실행
10966정성태5/12/201632069.NET Framework: 584. C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (1) - 기본 [1]파일 다운로드1
10965정성태5/12/201624083디버깅 기술: 81. try/catch로 조용히 사라진 예외를 파악하고 싶다면?
10964정성태5/12/201622700오류 유형: 331. ASP.NET에서 System.BadImageFormatException 예외가 발생하는 경우
10963정성태5/11/201624963VS.NET IDE: 107. Visual Studio 2015의 "DTAR_..." 특수 폴더가 생성되는 문제파일 다운로드2
10962정성태5/11/201624994오류 유형: 330. Visual Studio 단위 테스트 시 DisconnectedContext 예외 발생
10961정성태5/11/201624844.NET Framework: 583. 문제 재현 - Managed Debugging Assistant 'DisconnectedContext' has detected a problem in '...'파일 다운로드1
10960정성태5/10/201622315오류 유형: 329. ATL 메서드 추가 마법사 창에서 8ce0000b 오류 발생
10959정성태5/9/201624880.NET Framework: 582. CLR Profiler - 별도 정의한 .NET 코드를 호출하도록 IL 코드 변경파일 다운로드1
10958정성태5/6/201651900개발 환경 구성: 284. "Let's Encrypt"에서 제공하는 무료 SSL 인증서를 IIS에 적용하는 방법 (1) [3]
10957정성태5/3/201627204오류 유형: 328. 윈도우 백업 시 오류 - 0x80780166 두 번째 이야기 [1]
10956정성태5/3/201622740Windows: 117. BitLocker - This device can't use a Trusted Platform Module.
10955정성태5/3/201629416.NET Framework: 581. C# - 순열(Permutation) 예제 코드파일 다운로드2
10954정성태5/3/201630377.NET Framework: 580. C# - 조합(Combination) 예제 코드 [2]파일 다운로드1
10953정성태5/2/201619878.NET Framework: 579. Assembly.LoadFrom으로 로드된 어셈블리의 JIT 컴파일 코드 공유?파일 다운로드1
10952정성태5/2/201622056.NET Framework: 578. 도메인 중립적인 어셈블리가 비-도메인 중립적인 어셈블리를 참조하는 경우파일 다운로드1
10951정성태5/2/201619950.NET Framework: 577. CLR Profiler로 살펴보는 SharedDomain의 모듈 로드 동작파일 다운로드1
10950정성태5/2/201626350.NET Framework: 576. 기본적인 CLR Profiler 소스 코드 설명 [2]파일 다운로드2
... 106  107  108  109  110  111  112  113  114  115  116  117  [118]  119  120  ...