Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cake.tool compat? #22

Closed
bonesoul opened this issue Dec 16, 2018 · 4 comments
Closed

cake.tool compat? #22

bonesoul opened this issue Dec 16, 2018 · 4 comments

Comments

@bonesoul
Copy link

issuing a dotnet cake

Could not load D:\source\psnbooster\build\tools\Addins\Cake.AWS.S3.0.6.6\lib\netstandard2.0\Cake.AWS.S3.dll (missing AWSSDK.S3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604)
D:/source/psnbooster/build/build.cake(212,9): error CS0103: The name 'S3Upload' does not exist in the current context
D:/source/psnbooster/build/build.cake(213,8): error CS0246: The type or namespace name 'UploadSettings' could not be found (are you missing a using directive or an assembly reference?)
D:/source/psnbooster/build/build.cake(218,19): error CS0103: The name 'S3CannedACL' does not exist in the current context
D:/source/psnbooster/build/build.cake(222,9): error CS0103: The name 'S3Upload' does not exist in the current context
D:/source/psnbooster/build/build.cake(223,8): error CS0246: The type or namespace name 'UploadSettings' could not be found (are you missing a using directive or an assembly reference?)
D:/source/psnbooster/build/build.cake(228,19): error CS0103: The name 'S3CannedACL' does not exist in the current context
Error: Error(s) occurred when compiling build script:
D:/source/psnbooster/build/build.cake(212,9): error CS0103: The name 'S3Upload' does not exist in the current context
D:/source/psnbooster/build/build.cake(213,8): error CS0246: The type or namespace name 'UploadSettings' could not be found (are you missing a using directive or an assembly reference?)
D:/source/psnbooster/build/build.cake(218,19): error CS0103: The name 'S3CannedACL' does not exist in the current context
D:/source/psnbooster/build/build.cake(222,9): error CS0103: The name 'S3Upload' does not exist in the current context
D:/source/psnbooster/build/build.cake(223,8): error CS0246: The type or namespace name 'UploadSettings' could not be found (are you missing a using directive or an assembly reference?)
D:/source/psnbooster/build/build.cake(228,19): error CS0103: The name 'S3CannedACL' does not exist in the current context

any ideas?

@SharpeRAD
Copy link
Owner

You haven't included the original cake file so it's very hard for me to give you a definitive answer. I would assume by the title that you're running it using the .net core global tool so my first question is what happens when you run the CLI it from the standard Powershell script?

v0.6.6 of Cake.AWS.S3 has a reference to AWSSDK.S3 v3.3.17.9, not v3.3.0.0 so what other addons are you trying to use in your script?

@bonesoul
Copy link
Author

hey there using the cake.tool (https://www.nuget.org/packages/Cake.Tool/)

when i run my build script with actual cake (https://www.nuget.org/packages/Cake) it all works fine.

here is my script for your reference;

// sample I:  https://github.com/fluentassertions/fluentassertions/blob/master/build.cake
// sample II: https://github.com/gtbuchanan/repo-template-cs/blob/master/build.cake

// packages to use

#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0"
#tool "nuget:?package=vswhere&Version=2.5.2"
#addin "Cake.AWS.S3&version=0.6.6"
#addin "Cake.Git&Version=0.19.0"
#addin "Cake.Discord&version=0.1.0"

// master configuration
var buildRoot =  MakeAbsolute(Directory("./")); // get current path.
var target = Argument("target", "Default"); // build target. default 
var configuration = Argument("configuration", "Release"); // build configuration. release.
var vsLatest  = VSWhereLatest(); // get the vs path.
var msBuildPathX64 = (vsLatest == null) ? null : vsLatest.CombineWithFilePath("./MSBuild/15.0/Bin/amd64/MSBuild.exe");

// build configuration
var isAzurePipelines = TFBuild.IsRunningOnVSTS || TFBuild.IsRunningOnTFS; // are we running over azure devops?
var isWindowsBuild = IsRunningOnWindows(); // are we running a windows based build?
 var isLocal = BuildSystem.IsLocalBuild; // are we running a local build?

// git configuration
var currentBranch = Argument<string>("currentBranch", GitBranchCurrent("../").FriendlyName);
var isStableBuild = string.Equals(currentBranch, "master", StringComparison.OrdinalIgnoreCase);
var version = GitVersion(new GitVersionSettings { UpdateAssemblyInfo = false }); // init gitversion.

// solution configuration.
var sourcesDir = MakeAbsolute(Directory("../src")); // source code folder [src/]
var solutionFile = MakeAbsolute(File("../PSNBooster.sln")); // solution file [src/PsnBooster.UI/PSNBooster.sln]
var testProjectFile = MakeAbsolute(File($"{sourcesDir}/PsnBooster.Core.Tests/PsnBooster.Core.Tests.csproj")); // test project file [src/PsnBooster.Core.Tests/PsnBooster.Core.Tests.csproj]
var solutionOutput = MakeAbsolute(Directory($"{sourcesDir}/PsnBooster.UI/bin/{configuration}")); // the output folder for solution [src/PsnBooster.UI/bin/Release]

// tools
var advancedInstallerExecutable = File(@"tools\Advanced Installer 15.5.1\bin\x86\AdvancedInstaller.com"); // advanced installer path.
var advancedInstallerConfig = $"{buildRoot}/setup.aip"; // advanced installer setup config - [build/setup.aip]

// target filenames.
var targetInstallerFilename = "psnbooster-" + version.FullSemVer + ".zip"; // [psnbooster-x.y.z.zip]
var targetPortableFilename = "psnbooster-portable-" + version.FullSemVer + ".zip"; // [psnbooster-portable-x.y.z.zip]

// artifact directories.
var artifactsDir = MakeAbsolute(Directory("./artifacts/")); // base artifacts dir - [build/artifacts/]
var buildArtifactsDir = MakeAbsolute(Directory($"{artifactsDir}/release")); // artifacts directory for the build [build/artifacts/release]
var installerArtifactsDir = MakeAbsolute(Directory($"{artifactsDir}/setup")); // artifacts directory for the build - [build/artifacts/setup]

// release paths.
var releasesRoot = MakeAbsolute(Directory($"./releases/{(isStableBuild ? "stable" : "development")}"));
var installerReleaseDir = MakeAbsolute(Directory($"{releasesRoot}/installer/")); // the output directory for installer releases [build/releases/stable|development/setup]
var portableReleaseDir = MakeAbsolute(Directory($"{releasesRoot}/portable/")); // the output directory for portable releases [build/releases/stable|development/portable]
var installerReleaseFile = MakeAbsolute(File($"{installerReleaseDir}/{targetInstallerFilename}")); // the actual release file - [build/releases/psnbooster-x.y.z.zip]
var portableReleaseFile = MakeAbsolute(File($"{portableReleaseDir}/{targetPortableFilename}")); // the actual portable release file - [build/releases/psnbooster-portable-x.y.z.zip]

// amazons 3 config.
var s3ReleaseRoot = $"releases/{(isStableBuild ? "stable" : "development")}"; // s3 release root - [releases/stable|development/]
var s3InstallerFile = $"{s3ReleaseRoot}/installer/{targetInstallerFilename}"; // uploaded s3 file - [releases/stable|developemnt/psnbooster-x.y.z.zip]
var s3PortableFile = $"{s3ReleaseRoot}/portable/{targetPortableFilename}"; // uploaded s3 file - [releases/stable|development/psnbooster-portable-x.y.z.zip]
var s3BaseUrl = "https://s3.eu-central-1.amazonaws.com/cdn.psnbooster.com/";

// artifact files.
var artifactInstallerFile = MakeAbsolute(File($"{installerArtifactsDir}/psnbooster-setup.exe")); // the setup file - [build/artifacts/setup/psnbooster-setup.exe]
var artifactZippedInstallerFile = MakeAbsolute(File($"{installerArtifactsDir}/{targetInstallerFilename}")); // the zip that contains setup file - [build/artifacts/setup/psnbooster-x.y.z.zip]
var artifactPortableFile = MakeAbsolute(File($"{installerArtifactsDir}/{targetPortableFilename}")); // the portable zip file - [build/artifacts/setup/psnbooster-portable-x.y.z.zip]

// discord config
var discordWebhookUrl = "https://discordapp.com/api/webhooks/524146916922228736/_kbXfugpLoGfLAhIgwHQkUpoMPX8oZtnrot_ia1BMAvq6fuY6qYGJl6yBi-KbU-0w4bF";

// logs
var msbuildLogFile = artifactsDir.ToString() + "./msbuild.log"; // logs for MSBuild [build/artifacts/msbuild.log]

// TASKS

Setup(context =>
{
	Information($"starting build for version {version.FullSemVer}..");
	Information($"building a {(isStableBuild ? "stable" : "development")} release..");
	if(isWindowsBuild) 
	{
		Information("-------------------------------------------------------------------");
		Information($"target installer filename: {targetInstallerFilename}");
		Information($"target portable filename: {targetPortableFilename}");
		Information("-------------------------------------------------------------------");
		Information($"solution file: {solutionFile}");
		Information($"solution output: {solutionOutput}");
		Information("-------------------------------------------------------------------");
		Information($"release installer: {installerReleaseFile}");
		Information($"release portable: {portableReleaseFile}");
		Information("-------------------------------------------------------------------");
		Information($"build artifacts: {buildArtifactsDir}");
		Information($"installer artifacts: {installerArtifactsDir}");
		Information($"artifact installer: {artifactInstallerFile}");
		Information($"artifact zipped installer: {artifactZippedInstallerFile}");
		Information($"artifact portable: {artifactPortableFile}");
		Information("-------------------------------------------------------------------");
		Information($"s3 release installer: {s3InstallerFile}");
		Information($"s3 release portable: {s3PortableFile}");
		Information("-------------------------------------------------------------------");
		Information($"advanced installer path: {advancedInstallerExecutable}, using config: {advancedInstallerConfig}");
	} else {
		Information("skipping an installer build as we are not on windows..");
	}
});


Task("Clean")
    .Does(() =>
	{
		Information("cleaning artifact directories..");
		CleanDirectory(solutionOutput); // clean the solution output directory before a re-compile.

		if(!isWindowsBuild) return; // if we are building on windows, skip folder cleaning stuff for creating artifacts.
		CleanDirectory(artifactsDir); // clean the artifacts directory.
		if (!DirectoryExists(installerReleaseDir)) CreateDirectory(installerReleaseDir); // create the releases dir if not exists..
		if (!DirectoryExists(portableReleaseDir)) CreateDirectory(portableReleaseDir); // create the releases dir if not exists..
		if (FileExists(installerReleaseFile)) DeleteFile(installerReleaseFile); // remove the release file if exists already.
		if (FileExists(portableReleaseFile)) DeleteFile(portableReleaseFile); // remove the release file if exists already.
		CreateDirectory(buildArtifactsDir); // create the artifact release dir.
		CreateDirectory(installerArtifactsDir); // create the artifact setup dir.
	});

Task("Restore")
    .IsDependentOn("Clean")
    .Does(() =>
	{
		// restore dotnet project's packages.
		DotNetCoreRestore(solutionFile.ToString(), new DotNetCoreRestoreSettings
		{
			NoCache = true,
			Verbosity = DotNetCoreVerbosity.Normal
		});
	
		if(!isWindowsBuild) return; // only restore .net packages on windows builds.

		// restore .net project's packages.
		NuGetRestore(solutionFile.ToString(), new NuGetRestoreSettings 
		{ 
			NoCache = true,
			Verbosity = NuGetVerbosity.Normal
		});
	});

Task("Build")
    .IsDependentOn("Restore")
    .Does(() =>
	{
		if(isWindowsBuild)
		{
		  // on windows host, build using msbuild.
		  MSBuild(solutionFile.ToString(), settings => {
				settings.Verbosity = Verbosity.Minimal;
				settings.ToolPath = msBuildPathX64;
				settings.ToolVersion = MSBuildToolVersion.VS2017;
				settings.SetConfiguration(configuration);
				settings.AddFileLogger(new MSBuildFileLogger {
					LogFile = msbuildLogFile,
					MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.All   
				});
			});
		}
		else
		{
			// else on *nix, use dotnet core.
			DotNetCoreBuild(testProjectFile.ToString(), new DotNetCoreBuildSettings {
				Configuration = configuration,
				Verbosity = DotNetCoreVerbosity.Minimal
			});

			// on linux / macos, use xbuild (mono)
			// XBuild(solutionFile.ToString(), settings => settings.SetConfiguration(configuration));
		}
	});

Task("Test")
    .IsDependentOn("Build")
    .Does(() =>
	{			
		DotNetCoreTest(solutionFile.ToString(), new DotNetCoreTestSettings { // run donet core tests.
			ArgumentCustomization = args => args.Append("--logger \"trx;LogFileName=TestResults.xml\"") // output test results as XML so that VSTS can pick it up
		});
	});

Task("Artifacts")
	.WithCriteria(isWindowsBuild == true) // skip building an installer on *nix based system.
    .IsDependentOn("Test")
    .Does(() =>
	{	
		// copy release files.
		var extensions = new string[] { ".exe", ".dll", ".yml", ".config" }; // file extensions to copy.
		var files = GetFiles(solutionOutput.ToString() + "/**/*.*").Where(f => extensions.Contains(f.GetExtension().ToLower())); // get the files.
		CopyFiles(files, buildArtifactsDir, true); // copy them to release dir.

		// create the portable zip.
		Information($"creating portable release file: {targetPortableFilename}..");
		var releaseFiles = GetFiles(buildArtifactsDir + "/**/*.*");
		Zip(buildArtifactsDir, artifactPortableFile, releaseFiles);
		// copy the output zip file to actual release directory.
		CopyFiles(artifactPortableFile.ToString(), portableReleaseDir);		

		// build installer package.
		Information($"creating zipped installer release file: {targetInstallerFilename}.. ");
		var setVersion = StartProcess(advancedInstallerExecutable, "/edit " + advancedInstallerConfig + " /SetVersion " + version.MajorMinorPatch); // set installer version.
		var buildInstaller = StartProcess(advancedInstallerExecutable, @"/build " + advancedInstallerConfig); // build the installer.	
		Zip(installerArtifactsDir, artifactZippedInstallerFile.ToString(), artifactInstallerFile.ToString()); // create the setup zip.

		// copy the output zip file to actual release directory.
		CopyFiles(artifactZippedInstallerFile.ToString(), installerReleaseDir);		
	});

Task("Upload")
	.WithCriteria(isWindowsBuild == true && !isLocal) // skip artifact uploads on *nix based systems & local builds. 
    .IsDependentOn("Artifacts")
    .Does(async () =>
	{		
		// upload the portable release file.
		Information($"uploading portable release: {targetPortableFilename}..");
		await S3Upload(portableReleaseFile, s3PortableFile,
			new UploadSettings()
				.SetAccessKey("S3KEY")
				.SetSecretKey("S3SECRET")
				.SetRegion("eu-central-1")
				.SetBucketName("bucket")
				.SetCannedACL(S3CannedACL.PublicRead));		

		// upload the installer release file.
		Information($"uploading setup release: {targetInstallerFilename}..");
		await S3Upload(installerReleaseFile, s3InstallerFile,
			new UploadSettings()
				.SetAccessKey("S3KEY")
				.SetSecretKey("S3SECRET")
				.SetRegion("eu-central-1")
				.SetBucketName("bucket")
				.SetCannedACL(S3CannedACL.PublicRead));

		var portableFileUrl = $"{s3BaseUrl}{s3PortableFile}";
		var installerFileUrl = $"{s3BaseUrl}{s3InstallerFile}";
	});

Teardown(context =>
{
		Information($"build done for version {version.FullSemVer}..");
		if(isAzurePipelines) TFBuild.Commands.UpdateBuildNumber(version.FullSemVer);
});


// Targets

Task("Default")
	.IsDependentOn("Clean")
	.IsDependentOn("Restore")
	.IsDependentOn("Build")
    .IsDependentOn("Test")
	.IsDependentOn("Artifacts")
	.IsDependentOn("Upload");

// Execution.

RunTarget(target);

@mabead
Copy link

mabead commented Jun 27, 2019

I had the same issue, I resolved it by using #addin nuget:?package=Cake.AWS.S3&version=0.6.8&loaddependencies=true (note the loaddependencies option). I think that the README should be modified to reflect this.

@SharpeRAD
Copy link
Owner

I've updated the ReadMe to mention the loaddependencies option 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants