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)
12354정성태10/2/202020742오류 유형: 660. Web Deploy (msdeploy.axd) 실행 시 오류 기록 [1]
12353정성태10/2/202010550개발 환경 구성: 518. 비주얼 스튜디오에서 IIS 웹 서버로 "Web Deploy"를 이용해 배포하는 방법
12352정성태10/2/202011038개발 환경 구성: 517. Hyper-V Internal 네트워크에 NAT을 이용한 인터넷 연결 제공
12351정성태10/2/202010548오류 유형: 659. Nox 실행이 안 되는 경우 - Unable to bind to the underlying transport for ...
12350정성태9/25/202014057Windows: 175. 윈도우 환경에서 클라이언트 소켓의 최대 접속 수 [2]파일 다운로드1
12349정성태9/25/20209018Linux: 32. Ubuntu 20.04 - docker를 위한 tcp 바인딩 추가
12348정성태9/25/20209695오류 유형: 658. 리눅스 docker - Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
12347정성태9/25/202023875Windows: 174. WSL 2의 네트워크 통신 방법 [4]
12346정성태9/25/20208949오류 유형: 657. IIS - http://localhost 방문 시 Service Unavailable 503 오류 발생
12345정성태9/25/20208682오류 유형: 656. iisreset 실행 시 "Restart attempt failed." 오류가 발생하지만 웹 서비스는 정상적인 경우파일 다운로드1
12344정성태9/25/20209863Windows: 173. 서비스 관리자에 "IIS Admin Service"가 등록되어 있지 않다면?
12343정성태9/24/202019418.NET Framework: 945. C# - 닷넷 응용 프로그램에서 메모리 누수가 발생할 수 있는 패턴 [5]
12342정성태9/24/202010750디버깅 기술: 171. windbg - 인스턴스가 살아 있어 메모리 누수가 발생하고 있는지 확인하는 방법
12341정성태9/23/20209889.NET Framework: 944. C# - 인스턴스가 살아 있어 메모리 누수가 발생하고 있는지 확인하는 방법파일 다운로드1
12340정성태9/23/20209615.NET Framework: 943. WPF - WindowsFormsHost를 담은 윈도우 생성 시 메모리 누수
12339정성태9/21/20209576오류 유형: 655. 코어 모드의 윈도우는 GUI 모드의 윈도우로 교체가 안 됩니다.
12338정성태9/21/20209122오류 유형: 654. 우분투 설치 시 "CHS: Error 2001 reading sector ..." 오류 발생
12337정성태9/21/202010440오류 유형: 653. Windows - Time zone 설정을 바꿔도 반영이 안 되는 경우
12336정성태9/21/202012935.NET Framework: 942. C# - WOL(Wake On Lan) 구현
12335정성태9/21/202022334Linux: 31. 우분투 20.04 초기 설정 - 고정 IP 및 SSH 설치
12334정성태9/21/20207777오류 유형: 652. windbg - !py 확장 명령어 실행 시 "failed to find python interpreter"
12333정성태9/20/20208225.NET Framework: 941. C# - 전위/후위 증감 연산자에 대한 오버로딩 구현 (2)
12332정성태9/18/202010252.NET Framework: 940. C# - Windows Forms ListView와 DataGridView의 예제 코드파일 다운로드1
12331정성태9/18/20209412오류 유형: 651. repadmin /syncall - 0x80090322 The target principal name is incorrect.
12330정성태9/18/202010454.NET Framework: 939. C# - 전위/후위 증감 연산자에 대한 오버로딩 구현 [2]파일 다운로드1
12329정성태9/16/202012345오류 유형: 650. ASUS 메인보드 관련 소프트웨어 설치 후 ArmouryCrate.UserSessionHelper.exe 프로세스 무한 종료 현상
... 46  47  48  49  50  [51]  52  53  54  55  56  57  58  59  60  ...