public void ProcessDeployment(string packageLocation, Models.PackagesPackageDeployment deployment, IBuildMessageWriter buildMessageWriter, INuGetProcess nuGetProcess, string nuGetExeFilePath)
        {
            // Match a unc or drive based location - Do a copy if found
            var regex = new Regex(@"^((\\\\[a-zA-Z0-9-]+\\[a-zA-Z0-9`~!@#$%^&(){}'._-]+([ ]+[a-zA-Z0-9`~!@#$%^&(){}'._-]+)*)|([a-zA-Z]:))(\\[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*)*\\?$");

            if (!regex.Match(deployment.path).Success)
            {
                var pushDestinationArgument = string.IsNullOrWhiteSpace(deployment.path) ?
                   string.Empty : string.Format("-s \"{0}\"", deployment.path);

                var arguments = string.Format("push \"{0}\" {1} {2}",
                                             packageLocation, deployment.apiKey, pushDestinationArgument);


                buildMessageWriter.WriteBuildMessage(string.Format("Push Arguments: {0}", arguments), BuildMessageImportance.High);

                nuGetProcess.RunNuGetProcess(nuGetExeFilePath, arguments, buildMessageWriter);

                return;
            }

            var fileName = Path.GetFileName(packageLocation);

            if (fileName != null)
            {
                var destinationFilePath = Path.Combine(deployment.path, fileName);

                File.Copy(packageLocation, destinationFilePath, true);
            }
        }
        public void ProcessPackage(Models.PackagesPackage package, 
            string nuGetExeFilePath, 
            INuGetProcess nuGetProcess, 
            string sourcesDirectory, 
            string buildDirectory,
            string dropFolder, 
            IWorkspaceContext workspaceContext, 
            IBuildMessageWriter buildMessageWriter, 
            ICodeActivityContext context, 
            string buildNumber,
            int buildNumberPrefex, 
            string inputVersion)
        {
            var nuspecFile = GetFile(workspaceContext, sourcesDirectory, buildDirectory, package.NuSpecPath, package.name + "-nuspec");

            if(!File.Exists(nuspecFile))
            {
                throw new Exception(string.Format("The nuspec file \"{0}\" doesn't exist. It was defined in package \"{1}\"", nuspecFile, package.name));
            }

            if(string.IsNullOrEmpty(package.OutputDirectory))
            {
                package.OutputDirectory = "Packages";
            }
            if(string.IsNullOrEmpty(package.AdditionalOptions))
            {
                package.AdditionalOptions = string.Empty;
            }
            
            var outputDirectory = Path.Combine(dropFolder, package.OutputDirectory);
            if(!Directory.Exists(outputDirectory))
            {
                Directory.CreateDirectory(outputDirectory);
            }
            var basePath = dropFolder;

            if(!string.IsNullOrEmpty(package.BasePath))
            {
                basePath = Path.Combine(basePath, package.BasePath);
            }

            string version = !string.IsNullOrEmpty(package.Version)
                    ? new VersionPatternConverter().Convert(buildNumber, buildNumberPrefex, package.Version)
                    : new VersionPatternConverter().Convert(buildNumber, buildNumberPrefex, inputVersion);
            string versionParameter = string.Empty;
            // if the nuspec has a version token, it is expecting us to set it from out global version number created
            if (GetNuSpecPackageVersion(nuspecFile).Equals("$version$", StringComparison.InvariantCultureIgnoreCase))
            {
                // the package expects us to set a version
                // if the defintion defines a version, use it, otherwise, use the global version number
                versionParameter = string.Format("-version {0}", version);
            }

            // if the nuspec file has a $inputVersion$ token, we need to replace it.
            var nuspec = File.ReadAllText(nuspecFile);
            if(nuspec.Contains("$inputVersion$"))
            {
                FileAttributes attributes = File.GetAttributes(nuspecFile);

                if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    File.SetAttributes(nuspecFile, attributes ^ FileAttributes.ReadOnly);

                File.Delete(nuspecFile);
                File.WriteAllText(nuspecFile, nuspec.Replace("$inputVersion$", version));
            }

            // TODO
            //package.PrePackagePowerShell

            var arguments = string.Format("pack \"{0}\" -OutputDirectory \"{1}\" -BasePath \"{2}\" {3} {4}", nuspecFile, outputDirectory, basePath, versionParameter, package.AdditionalOptions).Trim();
            buildMessageWriter.WriteBuildMessage(string.Format("Calling nuget with arguments: {0}", arguments), BuildMessageImportance.High);
            nuGetProcess.RunNuGetProcess(nuGetExeFilePath, arguments, buildMessageWriter);

            // TODO
            //package.PreDeployPowerShell

            if(package.Deployments != null && package.Deployments.Length > 0)
            {
                var packageLocation = string.Empty;
                var pattern = GetNuSpecPackageName(nuspecFile) + "*.nupkg";
                var files = new DirectoryInfo(outputDirectory).GetFiles(pattern).ToList();

                if(files.Count > 1)
                {
                    context.AddBuildError(string.Format("An attempt was made to deploy but there was more than 1 package found in the directory \"{0}\" matching the pattern \"{1}\".", outputDirectory, pattern));
                }else if(files.Count == 0)
                {
                    context.AddBuildError(string.Format("An attempt was made to deploy but there was no package found in the directory \"{0}\" matching the pattern \"{1}\".", outputDirectory, pattern));
                }else
                {
                    packageLocation = files[0].FullName;
                }

                if(!string.IsNullOrEmpty(packageLocation) && File.Exists(packageLocation))
                {
                    foreach (var deployment in package.Deployments)
                    {
                        ProcessDeployment(packageLocation, deployment, buildMessageWriter, nuGetProcess, nuGetExeFilePath);
                    }
                }
            }
        }