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를 활용하는 방법을 설명하고 있습니다.
정성태

1  2  3  4  5  6  7  8  9  10  11  [12]  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13330정성태4/26/20233493Windows: 247. Win32 C/C++ - CS_GLOBALCLASS 설명
13329정성태4/24/20233714Windows: 246. Win32 C/C++ - 직접 띄운 대화창 템플릿을 위한 Modal 메시지 루프 생성파일 다운로드1
13328정성태4/19/20233390VS.NET IDE: 184. Visual Studio - Fine Code Coverage에서 동작하지 않는 Fake/Shim 테스트
13327정성태4/19/20233798VS.NET IDE: 183. C# - .NET Core/5+ 환경에서 Fakes를 이용한 단위 테스트 방법
13326정성태4/18/20235213.NET Framework: 2109. C# - 닷넷 응용 프로그램에서 SQLite 사용 (System.Data.SQLite) [1]파일 다운로드1
13325정성태4/18/20234509스크립트: 48. 파이썬 - PostgreSQL의 with 문을 사용한 경우 연결 개체 누수
13324정성태4/17/20234322.NET Framework: 2108. C# - Octave의 "save -binary ..."로 생성한 바이너리 파일 분석파일 다운로드1
13323정성태4/16/20234267개발 환경 구성: 677. Octave에서 Excel read/write를 위한 io 패키지 설치
13322정성태4/15/20235041VS.NET IDE: 182. Visual Studio - 32비트로만 빌드된 ActiveX와 작업해야 한다면?
13321정성태4/14/20233834개발 환경 구성: 676. WSL/Linux Octave - Python 스크립트 연동
13320정성태4/13/20233808개발 환경 구성: 675. Windows Octave 8.1.0 - Python 스크립트 연동
13319정성태4/12/20234292개발 환경 구성: 674. WSL 2 환경에서 GNU Octave 설치
13318정성태4/11/20234118개발 환경 구성: 673. JetBrains IDE에서 "Squash Commits..." 메뉴가 비활성화된 경우
13317정성태4/11/20234231오류 유형: 855. WSL 2 Ubuntu 20.04 - error: cannot communicate with server: Post http://localhost/v2/snaps/...
13316정성태4/10/20233558오류 유형: 854. docker-compose 시 "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" 오류 발생
13315정성태4/10/20233754Windows: 245. Win32 - 시간 만료를 갖는 컨텍스트 메뉴와 윈도우 메시지의 영역별 정의파일 다운로드1
13314정성태4/9/20233837개발 환경 구성: 672. DosBox를 이용한 Turbo C, Windows 3.1 설치
13313정성태4/9/20233924개발 환경 구성: 671. Hyper-V VM에 Turbo C 2.0 설치 [2]
13312정성태4/8/20233939Windows: 244. Win32 - 시간 만료를 갖는 MessageBox 대화창 구현 (개선된 버전)파일 다운로드1
13311정성태4/7/20234452C/C++: 163. Visual Studio 2022 - DirectShow 예제 컴파일(WAV Dest)
13310정성태4/6/20234033C/C++: 162. Visual Studio - /NODEFAULTLIB 옵션 설정 후 수동으로 추가해야 할 library
13309정성태4/5/20234212.NET Framework: 2107. .NET 6+ FileStream의 구조 변화
13308정성태4/4/20234103스크립트: 47. 파이썬의 time.time() 실숫값을 GoLang / C#에서 사용하는 방법
13307정성태4/4/20233874.NET Framework: 2106. C# - .NET Core/5+ 환경의 Windows Forms 응용 프로그램에서 HINSTANCE 구하는 방법
13306정성태4/3/20233671Windows: 243. Win32 - 윈도우(cbWndExtra) 및 윈도우 클래스(cbClsExtra) 저장소 사용 방법
13305정성태4/1/20234035Windows: 242. Win32 - 시간 만료를 갖는 MessageBox 대화창 구현 (쉬운 버전)파일 다운로드1
1  2  3  4  5  6  7  8  9  10  11  [12]  13  14  15  ...