Skip to content

Commit 32a9d13

Browse files
authored
Build package for NuGet (#28)
* Add csproj that enables nuget packing * Add a changelog * Add a nuget deploy workflow * update download-artifact * I have no idea what "username" should be for an organization??? * Try this * fix path * whitespace??? * fix secret * Use username for namespace? * publish to nuget * don't shallow clone * Fix props importing when used from nuget * don't write dll to nuget package * don't warn about not including a DLL there might be a better way to do this but hell if I know what it is * document how to use
1 parent 0cb7fca commit 32a9d13

File tree

7 files changed

+145
-2
lines changed

7 files changed

+145
-2
lines changed

.github/workflows/nuget.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Build for NuGet
2+
3+
on:
4+
push:
5+
tags:
6+
- '*.*.*'
7+
branches:
8+
- 'main'
9+
paths:
10+
- '**/*.csproj'
11+
- '**/*.props'
12+
- '**/*.targets'
13+
- '.github/workflows/nuget.yml'
14+
pull_request:
15+
paths:
16+
- '**/*.csproj'
17+
- '**/*.props'
18+
- '**/*.targets'
19+
- '.github/workflows/nuget.yml'
20+
workflow_dispatch:
21+
22+
env:
23+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
24+
DOTNET_NOLOGO: true
25+
NuGetDirectory: ${{ github.workspace}}/nuget
26+
27+
jobs:
28+
build:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0 # get full history, not shallow clone
34+
35+
- name: Setup .NET
36+
uses: actions/setup-dotnet@v4
37+
with:
38+
dotnet-version: 8.0.x
39+
40+
- name: Build
41+
run: dotnet build KSPBuildTools.csproj
42+
43+
- name: Package
44+
run: dotnet pack KSPBuildTools.csproj --configuration Release --output ${{ env.NuGetDirectory }}
45+
46+
- uses: actions/upload-artifact@v4
47+
with:
48+
name: nuget-package
49+
if-no-files-found: error
50+
path: ${{ env.NuGetDirectory }}/*.nupkg
51+
52+
deploy-nuget:
53+
runs-on: ubuntu-latest
54+
needs: [ build ]
55+
environment:
56+
name: "NuGet"
57+
url: "https://www.nuget.org/packages/KSPBuildTools"
58+
if: github.event_name == 'push'
59+
steps:
60+
- name: Setup .NET
61+
uses: actions/setup-dotnet@v4
62+
with:
63+
dotnet-version: 8.0.x
64+
65+
- uses: actions/download-artifact@v4
66+
with:
67+
name: nuget-package
68+
path: ${{ env.NuGetDirectory }}
69+
70+
- name: Publish Package to NuGet
71+
run: >-
72+
dotnet nuget push ${{ env.NuGetDirectory }}/*.nupkg
73+
--api-key ${{ secrets.NUGET_API_KEY }}
74+
--source https://api.nuget.org/v3/index.json
75+
76+
- name: Authenticate with Github
77+
run: >-
78+
dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }}
79+
--store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
80+
81+
- name: Publish Package to Github
82+
run: |
83+
dotnet nuget push --source "github" ${{ env.NuGetDirectory }}/*.nupkg

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# dotnet artifacts
2+
bin
3+
obj
4+
*.nupkg

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file

KSPBuildTools.csproj

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<Target Name="Build" />
4+
<Target Name="Rebuild" />
5+
6+
<!-- NuGet dependencies -->
7+
<ItemGroup>
8+
<!-- MinVer for project versioning. necessary for nuget -->
9+
<PackageReference Include="MinVer" Version="5.0.0">
10+
<PrivateAssets>all</PrivateAssets>
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
12+
</PackageReference>
13+
</ItemGroup>
14+
15+
<PropertyGroup>
16+
<TargetFramework>netstandard2.0</TargetFramework>
17+
<LangVersion>7.3</LangVersion>
18+
<IsPackable>true</IsPackable>
19+
<PlatformTarget>x64</PlatformTarget>
20+
<NoWarn>1701;1702;CS0649;CS1591;NU5128</NoWarn>
21+
<AssemblyCopyright>2024 KSPModdingLibs Contributors</AssemblyCopyright>
22+
<AssemblyName>KSPBuildTools</AssemblyName>
23+
<RepoRootPath>$(ProjectDir)</RepoRootPath>
24+
<PackageId>KSPBuildTools</PackageId>
25+
<PackageReadmeFile>README.md</PackageReadmeFile>
26+
<Authors>KSPModdingLibs Contributors</Authors>
27+
<IncludeBuildOutput>false</IncludeBuildOutput>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<None Include="KSPCommon.props" Pack="True" PackagePath="build/KSPBuildTools.props" />
32+
<None Include="KSPCommon.targets" Pack="True" PackagePath="build/KSPBuildTools.targets" />
33+
<None Include="README.md" Pack="True" PackagePath="/"/>
34+
</ItemGroup>
35+
</Project>

KSPCommon.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<KSPCommonPropsImported>true</KSPCommonPropsImported>
5+
</PropertyGroup>
36

47
<!--import solution-wide props if it exists -->
58
<Import Condition=" Exists('$(SolutionDir)$(SolutionName).props') " Project="$(SolutionDir)$(SolutionName).props"/>

KSPCommon.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Condition=" '$(KSPCommonPropsImported)' == '' " Project="KSPCommon.props"/>
3+
<Import Condition=" '$(KSPCommonPropsImported)' == '' And Exists('$(MSBuildThisFileDirectory)KSPCommon.props') " Project="$(MSBuildThisFileDirectory)KSPCommon.props"/>
44

55
<!-- Pre/post build targets -->
66
<Target Name="BeforeBuildScript" BeforeTargets="Build">

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
KSP Build Tools
2+
===============
3+
14
This repository aims to provide a common set of tools for developing mods for Kerbal Space Program. Note that it's still in "alpha" stages so expect things to change or break.
25

36
To use it, either:
47

8+
* Reference this package in your csproj
9+
10+
run
11+
`dotnet add package KSPBuildTools`
12+
13+
or add the following to your csproj
14+
```xml
15+
<ItemGroup>
16+
<PackageReference Include="KSPBuildTools" Version="0.0.0-alpha.0.214" />
17+
</ItemGroup>
18+
```
19+
520
* Add this repository as a submodule:
621

722
`git submodule add https://github.com/KSPModdingLibs/KSPBuildTools.git`
@@ -27,7 +42,7 @@ What it does:
2742
- Includes a target for installing dependencies with CKAN
2843
- Designed to be used by the [Build github workflow](#compile-action)
2944

30-
To use it, import `KSPCommon.targets` in your .csproj file after it imports Microsoft.CSharp.targets. You should remove ALL the existing assembly references to `System`, `Assembly-CSharp`, and `Unity`.
45+
If not using a PackageReference, import `KSPCommon.targets` in your .csproj file after it imports Microsoft.CSharp.targets. You should remove ALL the existing assembly references to `System`, `Assembly-CSharp`, and `Unity`.
3146

3247
```xml
3348
<Import Project="$(MSBuildToolsPath)/Microsoft.CSharp.targets" />

0 commit comments

Comments
 (0)