1

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.

Miguel Moura
  • 36,732
  • 85
  • 259
  • 481

1 Answers1

2
  1. For this sort of thing I use a combination of GitVersion and MagicChunks both of which have Cake Aliases available. Gitversion is used to assert the version number of the repo, and MagicChunks is used to update different sections of xml, json files, etc.
  2. Can you confirm exactly what you mean here? Are you talking about commiting changes back into the GitHub repository? If so, you might want to take a look at the Cake.Git addin. Or, if you are talking about pushing files to a GitHub release, you might want to take a look at the GitReleaseManager aliases.
  3. Once you have the NuGet package, you should be able to use the NuGetPush alias to push the package to MyGet. You will need to set the Source property of the NuGetPushSettings class.

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.

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
  • 1. So you manual add files and commits to your local repository and then ue the build script to push them letting GitVersion getting the commit message and info? I am asking this because I was including in my Cake script GitCommit (http://cakebuild.net/api/Cake.Git/GitCommit/) so every time I build it a commit was created and pushed to the remote repository. But my problem was how to define the commit message in this case. Do you understand my question? – Miguel Moura Mar 13 '17 at 10:05
  • 2. I am talking about comming changes and pushing them to the Github repository and also pushing releases with version as a Tag when I need to do so. I was considering having 2 targets: "Default" to Commit and Push changes with a change in version patch but no Github Tag and no push no Nuget. And have another target "Release" that would add a Tag and push it also to Nuget. Does it make sense? – Miguel Moura Mar 13 '17 at 10:08
  • I have added some additional notes into my answer above. – Gary Ewan Park Mar 13 '17 at 11:09