Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)
(시리즈 글이 4개 있습니다.)
개발 환경 구성: 296. .NET Core 프로젝트를 NuGet Gallery에 배포하는 방법
; https://www.sysnet.pe.kr/2/0/11034

.NET Framework: 793. C# - REST API를 이용해 NuGet 저장소 제어
; https://www.sysnet.pe.kr/2/0/11696

개발 환경 구성: 423. NuGet 패키지 제작 - Native와 Managed DLL을 분리하는 방법
; https://www.sysnet.pe.kr/2/0/11793

개발 환경 구성: 494. NuGet - nuspec의 패키지 스키마 버전(네임스페이스) 업데이트 방법
; https://www.sysnet.pe.kr/2/0/12234




.NET Core 프로젝트를 NuGet Gallery에 배포하는 방법

이미 다른 글이 있지만. ^^

Nuget Gallery 서버에 내 패키지 등록하기 : Uploading package to nugget gallery
; http://funnygangstar.tistory.com/entry/Nuget-Gallery-%EC%84%9C%EB%B2%84%EC%97%90-%EB%82%B4-%ED%8C%A8%ED%82%A4%EC%A7%80-%EB%93%B1%EB%A1%9D%ED%95%98%EA%B8%B0-Uploading-package-to-nugget-gallery

.NET Core 프로젝트의 경우 "dotnet.exe pack" 명령어로 좀 더 쉽게 할 수 있는 방법이 제공됩니다. 이 글에서는 그 방법을 정리해 봤습니다.




우선, NuGet Gallery에 올릴 예제가 필요한데요. 대충 Visual Studio에서 .NET Core 라이브러리를 만들어줍니다. 그다음, 명령행에서 해당 프로젝트의 project.json 폴더가 있는 폴더로 이동해 "dotnet.exe pack" 명령을,

dotnet-pack
; https://learn.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-pack

다음과 같이 실행해주기만 하면 됩니다. ^^

D:\MyNuGet\GosperCombination\src\GosperCombination>dotnet pack
Project GosperCombination (.NETStandard,Version=v1.6) was previously compiled. Skipping compilation.
Producing nuget package "GosperCombination.1.0.0" for GosperCombination
GosperCombination -> D:\MyNuGet\GosperCombination\src\GosperCombination\bin\Debug\GosperCombination.1.0.0.nupkg
Producing nuget package "GosperCombination.1.0.0.symbols" for GosperCombination
GosperCombination -> D:\MyNuGet\GosperCombination\src\GosperCombination\bin\Debug\GosperCombination.1.0.0.symbols.nupkg

보는 바와 같이 GosperCombination.1.0.0.nupkg 라는 파일이 생성되었는데요. 이것은 바이너리 파일로 NuGet Gallery에 올릴 .zip 파일이라고 보시면 됩니다. 실제로 확장자만 변경해서 zip 프로그램으로 내용을 볼 수 있습니다.

dotnet_pack_1.png

\
    [Content_Types].xml
    GosperCombination.nuspec

    \_rels
        .rels
		
    \lib
        \netstandard1.6
            GosperCombination.dll




이제 NuGet 패키지를 생성했으니, NuGet Gallery에 올리는 일만 남았습니다. 우선 nuget.exe 파일이 필요합니다.

NuGet - Installing
; https://docs.nuget.org/consume/command-line-reference
; https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

위의 파일을 다운로드 받은 경로를 PATH 환경 변수에 등록해 주면 이후 편하게 사용할 수 있습니다.

그다음, NuGet 사이트에 방문해서 회원 가입을 한 후,

NuGet Gallery
; http://nuget.org

로그인을 하면 우측 상단에 자신의 ID에 해당하는 링크를 클릭해 "My NuGet.org Account" 화면으로 이동합니다. 거기서 API Key를 복사한 후 다음과 같이 실행해 줍니다.

D:\MyNuGet>nuget setApiKey ????????-????-????-????-???????????? -Source https://www.nuget.org/api/v2/package
The API Key '????????-????-????-????-????????????' was saved for 'https://www.nuget.org/api/v2/package'.

이렇게 한 번만 해주면, 이후 해당 컴퓨터에서는 API Key를 재차 입력할 필요가 없습니다. 따라서, 우리가 만든 GosperCombination.1.0.0.nupkg 패키지를 다음과 같은 명령어로 간단하게 업로드할 수 있습니다.

D:\MyNuGet\GosperCombination\src\GosperCombination\bin\Debug>nuget push GosperCombination.1.0.0.nupkg -Source https://www.nuget.org/api/v2/package
Pushing GosperCombination.1.0.0.nupkg to 'https://www.nuget.org/api/v2/package'...
  PUT https://www.nuget.org/api/v2/package/
  Created https://www.nuget.org/api/v2/package/ 7672ms
Your package was pushed.
Pushing GosperCombination.1.0.0.symbols.nupkg to the symbol server (https://nuget.smbsrc.net/)...
  PUT https://nuget.smbsrc.net/api/v2/package/
  OK https://nuget.smbsrc.net/api/v2/package/ 3056ms
Your package was pushed.

그럼, 이렇게 등록된 페이지를 볼 수 있습니다. ^^

GosperCombination 1.0.0 
; https://www.nuget.org/packages/GosperCombination/

등록도 했으니, Visual Studio에서 사용도 해봐야겠지요. ^^ 간단하게 .NET Core Console 프로젝트를 만들고 NuGet Package Manager를 이용해 "Install-Package GosperCombination" 명령을 실행한 후 다음과 같이 코딩을 해주면 됩니다.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Gosper;

namespace ConsoleApp1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] items = new string[] { "ant", "bug", "cat", "dog", "elk" };

            int choose = 3;
            Combination c = new Combination(items, choose);

            foreach (var elems in c.Successor())
            {
                // ...[생략]...
            }
        }
    }
}

NuGet 패키지가 재미있는 것은, 위의 소스 코드를 Visual Studio에서 빌드해도 대상 폴더에는 "ConsoleApp1.dll" 파일만 생성된다는 점입니다. 즉, GosperCombination.dll 파일이 출력 폴더에는 없다는 건데요. 그래도 Visual Studio에서 실행해 보면 정상적으로 구동됩니다. 어떻게 이것이 가능할까요?

살펴보면, 추가한 NuGet 패키지의 바이너리는 다음의 경로에서 찾을 수 있습니다.

%USERPROFILE%\.nuget\packages\GosperCombination\1.0.0\lib\netstandard1.6

그리고, dotnet.exe는 설치된 NuGet 로컬 폴더를 마치 기존의 GAC(Global Assembly Cache)처럼 인식해서 전역 어셈블리 저장소로써 다루고 있는 것입니다.

문제는, 해당 NuGet 패키지는 개발자의 PC에만 있기 때문에 그것을 사용하는 프로그램의 DLL 파일을 다른 PC에 배포해서 실행하면 당연히 오류가 발생합니다. 실제로 ConsoleApp1.dll 파일만 복사해서 실행하면 이런 오류가 발생합니다. (이 오류는 ConsoleApp1.runtimeconfig.json 파일을 함께 배포하지 않은 경우에 발생합니다.)

C:\temp> dotnet ConsoleApp1.dll
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\temp'.

즉, 다른 컴퓨터에 배포하려면 모든 의존성을 해결해주는 작업이 필요한데 이럴 때 사용할 명령어가 바로 "dotnet publish" 입니다. (Visual Studio의 경우 솔루션 탐색기에서 프로젝트를 마우스 우 클릭 후 "Publish..." 메뉴를 선택하면 됩니다.)

C:\ConsoleApp1\src\ConsoleApp1>dotnet publish
Publishing ConsoleApp1 for .NETCoreApp,Version=v1.0
Project ConsoleApp1 (.NETCoreApp,Version=v1.0) will be compiled because inputs were modified
Compiling ConsoleApp1 for .NETCoreApp,Version=v1.0

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:01.0110965


publish: Published to C:\ConsoleApp1\src\ConsoleApp1\bin\Debug\netcoreapp1.0\publish
Published 1/1 projects successfully

위와 같이, project.json 파일이 있는 곳에서 "dotnet publish"를 실행해 주면 의존성까지 고려한 바이너리를 "C:\ConsoleApp1\src\ConsoleApp1\bin\Debug\netcoreapp1.0\publish" 폴더에 출력해 줍니다. 그리고, 이것을 다른 PC에 복사하면 끝!




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 12/22/2023]

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

비밀번호

댓글 작성자
 



2016-08-29 06시57분
[강준] 좋은 자료 감사합니다. api 키를 매번 입력했는데 저런 방법도 있군요 ^^
[guest]
2022-04-02 10시35분
모은 dll 파일을 NuGet Package로 만들기
; https://docs.google.com/document/d/e/2PACX-1vRPFq05IONENb0S7_-TNoTNr3bG5p6aeK2xWrpv7dSpXOujTMhAODfWW-hieJo09wb2-cSZ-wBbNS3M/pub

위의 글은 Microsoft Store에서 배포하는 NuGet Package Explorer를 활용하는 방법을 설명하고 있습니다.
정성태

... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...
NoWriterDateCnt.TitleFile(s)
12126정성태1/25/202010732.NET Framework: 880. C# - PE 파일로부터 IMAGE_COR20_HEADER 및 VTableFixups 테이블 분석파일 다운로드1
12125정성태1/24/20208601VS.NET IDE: 141. IDE0019 - Use pattern matching
12124정성태1/23/202010435VS.NET IDE: 140. IDE1006 - Naming rule violation: These words must begin with upper case characters: ...
12123정성태1/23/202011910웹: 39. Google Analytics - gtag 함수를 이용해 페이지 URL 수정 및 별도의 이벤트 생성 방법 [2]
12122정성태1/20/20208892.NET Framework: 879. C/C++의 UNREFERENCED_PARAMETER 매크로를 C#에서 우회하는 방법(IDE0060 - Remove unused parameter '...')파일 다운로드1
12121정성태1/20/20209426VS.NET IDE: 139. Visual Studio - Error List: "Could not find schema information for the ..."파일 다운로드1
12120정성태1/19/202010877.NET Framework: 878. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 네 번째 이야기(IL 코드로 직접 구현)파일 다운로드1
12119정성태1/17/202010908디버깅 기술: 160. Windbg 확장 DLL 만들기 (3) - C#으로 만드는 방법
12118정성태1/17/202011535개발 환경 구성: 466. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 세 번째 이야기 [1]
12117정성태1/15/202010563디버깅 기술: 159. C# - 디버깅 중인 프로세스를 강제로 다른 디버거에서 연결하는 방법파일 다운로드1
12116정성태1/15/202011047디버깅 기술: 158. Visual Studio로 디버깅 시 sos.dll 확장 명령어를 (비롯한 windbg의 다양한 기능을) 수행하는 방법
12115정성태1/14/202010831디버깅 기술: 157. C# - PEB.ProcessHeap을 이용해 디버깅 중인지 확인하는 방법파일 다운로드1
12114정성태1/13/202012685디버깅 기술: 156. C# - PDB 파일로부터 심벌(Symbol) 및 타입(Type) 정보 열거 [1]파일 다운로드3
12113정성태1/12/202013300오류 유형: 590. Visual C++ 빌드 오류 - fatal error LNK1104: cannot open file 'atls.lib' [1]
12112정성태1/12/20209909오류 유형: 589. PowerShell - 원격 Invoke-Command 실행 시 "WinRM cannot complete the operation" 오류 발생
12111정성태1/12/202013107디버깅 기술: 155. C# - KernelMemoryIO 드라이버를 이용해 실행 프로그램을 숨기는 방법(DKOM: Direct Kernel Object Modification) [16]파일 다운로드1
12110정성태1/11/202011700디버깅 기술: 154. Patch Guard로 인해 블루 스크린(BSOD)가 발생하는 사례 [5]파일 다운로드1
12109정성태1/10/20209629오류 유형: 588. Driver 프로젝트 빌드 오류 - Inf2Cat error -2: "Inf2Cat, signability test failed."
12108정성태1/10/20209676오류 유형: 587. Kernel Driver 시작 시 127(The specified procedure could not be found.) 오류 메시지 발생
12107정성태1/10/202010652.NET Framework: 877. C# - 프로세스의 모든 핸들을 열람 - 두 번째 이야기
12106정성태1/8/202012029VC++: 136. C++ - OSR Driver Loader와 같은 Legacy 커널 드라이버 설치 프로그램 제작 [1]
12105정성태1/8/202010701디버깅 기술: 153. C# - PEB를 조작해 로드된 DLL을 숨기는 방법
12104정성태1/7/202011424DDK: 9. 커널 메모리를 읽고 쓰는 NT Legacy driver와 C# 클라이언트 프로그램 [4]
12103정성태1/7/202014093DDK: 8. Visual Studio 2019 + WDK Legacy Driver 제작- Hello World 예제 [1]파일 다운로드2
12102정성태1/6/202011744디버깅 기술: 152. User 권한(Ring 3)의 프로그램에서 _ETHREAD 주소(및 커널 메모리를 읽을 수 있다면 _EPROCESS 주소) 구하는 방법
12101정성태1/5/202011105.NET Framework: 876. C# - PEB(Process Environment Block)를 통해 로드된 모듈 목록 열람
... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...