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)
13373정성태6/19/20234398오류 유형: 865. 파이썬 - pymssql 설치 관련 오류 정리
13372정성태6/15/20233110개발 환경 구성: 682. SQL Server TLS 통신을 위해 사용되는 키 길이 확인 방법
13371정성태6/15/20233132개발 환경 구성: 681. openssl - 인증서 버전(V1 / V3)
13370정성태6/14/20233295개발 환경 구성: 680. C# - Ubuntu + Microsoft.Data.SqlClient + SQL Server 2008 R2 연결 방법 - TLS 1.2 지원
13369정성태6/13/20233092개발 환경 구성: 679. PyCharm(을 비롯해 JetBrains에 속한 여타) IDE에서 내부 Window들의 탭이 없어진 경우
13368정성태6/13/20233225개발 환경 구성: 678. openssl로 생성한 인증서를 SQL Server의 암호화 인증서로 설정하는 방법
13367정성태6/10/20233331오류 유형: 864. openssl로 만든 pfx 인증서를 Windows Server 2016 이하에서 등록 시 "The password you entered is incorrect" 오류 발생
13366정성태6/10/20233130.NET Framework: 2128. C# - 윈도우 시스템에서 지원하는 암호화 목록(Cipher Suites) 나열파일 다운로드1
13365정성태6/8/20232896오류 유형: 863. MODIFY FILE encountered operating system error 112(failed to retrieve text for this error. Reason: 15105)
13364정성태6/8/20233677.NET Framework: 2127. C# - Ubuntu + Microsoft.Data.SqlClient + SQL Server 2008 R2 연결 방법 [1]
13363정성태6/7/20233241스크립트: 49. 파이썬 - "Transformers (신경망 언어모델 라이브러리) 강좌" - 1장 2절 코드 실행 결과
13362정성태6/1/20233164.NET Framework: 2126. C# - 서버 측의 요청 제어 (Microsoft.AspNetCore.RateLimiting)파일 다운로드1
13361정성태5/31/20233638오류 유형: 862. Facebook - ASP.NET/WebClient 사용 시 graph.facebook.com/me 호출에 대해 403 Forbidden 오류
13360정성태5/31/20233036오류 유형: 861. WSL/docker - failed to start shim: start failed: io.containerd.runc.v2: create new shim socket
13359정성태5/19/20233352오류 유형: 860. Docker Desktop - k8s 초기화 무한 반복한다면?
13358정성태5/17/20233660.NET Framework: 2125. C# - Semantic Kernel의 Semantic Memory 사용 예제 [1]파일 다운로드1
13357정성태5/16/20233464.NET Framework: 2124. C# - Semantic Kernel의 Planner 사용 예제파일 다운로드1
13356정성태5/15/20233769DDK: 10. Device Driver 테스트 설치 관련 오류 (Code 37, Code 31) 및 인증서 관련 정리
13355정성태5/12/20233685.NET Framework: 2123. C# - Semantic Kernel의 ChatGPT 대화 구현 [1]파일 다운로드1
13354정성태5/12/20233956.NET Framework: 2122. C# - "Use Unicode UTF-8 for worldwide language support" 설정을 한 경우, 한글 입력이 '\0' 문자로 처리
13352정성태5/12/20233569.NET Framework: 2121. C# - Semantic Kernel의 대화 문맥 유지파일 다운로드1
13351정성태5/11/20234070VS.NET IDE: 185. Visual Studio - 원격 Docker container 내에 실행 중인 응용 프로그램에 대한 디버깅 [1]
13350정성태5/11/20233322오류 유형: 859. Windows Date and Time - Unable to continue. You do not have permission to perform this task
13349정성태5/11/20233661.NET Framework: 2120. C# - Semantic Kernel의 Skill과 Function 사용 예제파일 다운로드1
13348정성태5/10/20233570.NET Framework: 2119. C# - Semantic Kernel의 "Basic Loading of the Kernel" 예제
13347정성태5/10/20233931.NET Framework: 2118. C# - Semantic Kernel의 Prompt chaining 예제파일 다운로드1
1  2  3  4  5  6  7  8  9  [10]  11  12  13  14  15  ...