I am building an ASP.NET Core 1.1 with .csproj file using Cake. I need to push the source to Github and publish the package to MyGet. At the moment I have the script:
String target = Argument<String>("target", "Default");
Task("Clean").Does(() => {
if (DirectoryExists("./build"))
DeleteDirectory("./build", true);
CreateDirectory("./build");
});
Task("Restore").Does(() => {
FilePathCollection projects = GetFiles("./**/*.csproj");
foreach(FilePath project in projects)
DotNetCoreRestore(project.FullPath);
});
Task("Build").IsDependentOn("Clean").IsDependentOn("Restore").Does(() => {
FilePathCollection projects = GetFiles("./**/*.csproj");
foreach(FilePath project in projects)
DotNetCoreBuild(project.FullPath);
});
Task("Test").IsDependentOn("Build").Does(() => {
FilePathCollection projects = GetFiles("./test/**/*.csproj");
foreach(FilePath project in projects)
DotNetCoreTest(project.FullPath);
});
Task("Pack").IsDependentOn("Test").Does(() => {
DotNetCorePack("./src/MyProject.csproj", new DotNetCorePackSettings { OutputDirectory = "./build/MyProject/" });
});
Task("Default").IsDependentOn("Pack");
RunTarget(target);
How can I do the following:
1. Increment the revision number based on the version of the csproj file;
2. Push the project to Github;
3. Push the package to MyGet.
Based on some of your comments, I am updating this answer slightly...
I typically don't use Cake to push changes back to the source control repository. Rather, the commits that I make into the source control repository cause my build to be triggered, typically using some form of Continuous Integration Server, like AppVeyor or TeamCity. That way, the commit message that you are asking about will always be known by the user, as they are making the commit, and will know what has changed. By using this approach, there are no automated commits in to the repository, and personally, I think that this is how it should be.
Based on the above, you would only need the Release target that you mention. As part of the build process, GitVersion will assert the version number, and allow you to create NuGet packages with that version number (which then doesn't require an additional commit into the repository) and then you can push out to NuGet.org, and GitHub.