Skip to content

Commit

Permalink
Updates the build script to the MSBuild project format
Browse files Browse the repository at this point in the history
  • Loading branch information
ecampidoglio committed Oct 23, 2017
1 parent 959d53b commit 614c5c0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
27 changes: 16 additions & 11 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,37 @@ Task("Clean")
Task("Restore-Packages")
.Does(() =>
{
DotNetCoreRestore();
DotNetCoreRestore(Paths.SolutionFile.FullPath);
});

Task("Compile")
.IsDependentOn("Restore-Packages")
.Does(() =>
{
DotNetCoreBuild(
Paths.ProjectDirectory,
new DotNetCoreBuildSettings
{
Configuration = configuration
});
var settings = new DotNetCoreBuildSettings
{
Configuration = configuration
};
if (IsRunningOnUnix())
{
settings.Framework = "netcoreapp1.0";
}
DotNetCoreBuild(Paths.ProjectFile.FullPath, settings);
});

Task("Version")
.Does(() =>
{
if (string.IsNullOrEmpty(packageVersion))
{
packageVersion = GetVersionFromProjectFile(Paths.ProjectDirectory);
packageVersion = GetVersionFromProjectFile(Context, Paths.ProjectFile);
Information($"Determined version {packageVersion} from the project file");
}
else
{
SetVersionToProjectFile(packageVersion, Paths.ProjectDirectory);
SetVersionToProjectFile(Context, Paths.ProjectFile, packageVersion);
Information($"Assigned version {packageVersion} to the project file");
}
});
Expand Down Expand Up @@ -71,7 +76,7 @@ Task("Test")
settings.Framework = "netcoreapp1.0";
}
DotNetCoreTest(Paths.TestsDirectory, settings);
DotNetCoreTest(Paths.TestProjectFile.FullPath, settings);
});

Task("Package")
Expand All @@ -80,7 +85,7 @@ Task("Package")
.Does(() =>
{
DotNetCorePack(
Paths.ProjectDirectory,
Paths.ProjectFile.FullPath,
new DotNetCorePackSettings
{
OutputDirectory = packageOutputDirectory,
Expand Down
5 changes: 3 additions & 2 deletions build/paths.cake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
public static class Paths
{
public static string ProjectDirectory => "src/Cake.Curl";
public static string TestsDirectory => "src/Cake.Curl.Tests";
public static FilePath SolutionFile => "src/Cake.Curl.sln";
public static FilePath ProjectFile => "src/Cake.Curl/Cake.Curl.csproj";
public static FilePath TestProjectFile => "src/Cake.Curl.Tests/Cake.Curl.Tests.csproj";
}
28 changes: 12 additions & 16 deletions build/version.cake
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#addin nuget:?package=Newtonsoft.Json&version=9.0.1

public static string GetVersionFromProjectFile(
DirectoryPath projectDirectory)
ICakeContext context,
FilePath projectFile)
{
var projectFilePath = projectDirectory.GetFilePath("project.json").FullPath;
var content = System.IO.File.ReadAllText(projectFilePath);
var project = Newtonsoft.Json.Linq.JObject.Parse(content);

return (string)project["version"];
return context.XmlPeek(
projectFile,
"/Project/PropertyGroup/Version/text()");
}

public static void SetVersionToProjectFile(
string version,
DirectoryPath projectDirectory)
ICakeContext context,
FilePath projectFile,
string version)
{
var projectFilePath = projectDirectory.GetFilePath("project.json").FullPath;
var content = System.IO.File.ReadAllText(projectFilePath);
var project = Newtonsoft.Json.Linq.JObject.Parse(content);

project["version"] = version;
System.IO.File.WriteAllText(projectFilePath, project.ToString());
context.XmlPoke(
projectFile,
"/Project/PropertyGroup/Version",
version);
}

0 comments on commit 614c5c0

Please sign in to comment.