private static int BuildDacpac(BuildOptions options) { // Wait for a debugger to attach WaitForDebuggerToAttach(options); // Set metadata for the package using var packageBuilder = new PackageBuilder(); packageBuilder.SetMetadata(options.Name, options.Version); // Set properties on the model (if defined) if (options.Property != null) { foreach (var propertyValue in options.Property) { string[] keyValuePair = propertyValue.Split('=', 2); packageBuilder.SetProperty(keyValuePair[0], keyValuePair[1]); } } // Build the empty model for the target SQL Server version packageBuilder.UsingVersion(options.SqlServerVersion); // Add references to the model if (options.Reference != null) { foreach (var reference in options.Reference) { string[] referenceDetails = reference.Split(';', 2, StringSplitOptions.RemoveEmptyEntries); if (referenceDetails.Length == 1) { packageBuilder.AddReference(referenceDetails[0]); } else { packageBuilder.AddExternalReference(referenceDetails[0], referenceDetails[1]); } } } // Add SqlCmdVariables to the package (if defined) if (options.SqlCmdVar != null) { packageBuilder.AddSqlCmdVariables(options.SqlCmdVar); } // Add input files by iterating through $Project.InputFiles.txt if (options.InputFile != null) { if (options.InputFile.Exists) { foreach (var line in File.ReadLines(options.InputFile.FullName)) { FileInfo inputFile = new FileInfo(line); // Validation occurs in AddInputFile packageBuilder.AddInputFile(inputFile); } } else { throw new ArgumentException($"No input files found, missing {options.InputFile.Name}"); } } //Add Warnings options packageBuilder.TreatTSqlWarningsAsErrors = options.WarnAsError; if (options.SuppressWarnings != null) { packageBuilder.AddWarningsToSuppress(options.SuppressWarnings); } // Add warnings suppressions for particular files through $Project.WarningsSuppression.txt if (options.SuppressWarningsListFile != null) { if (options.SuppressWarningsListFile.Exists) { foreach (var line in File.ReadLines(options.SuppressWarningsListFile.FullName)) { //Checks if there are suppression warnings list var parts = line.Split('|', StringSplitOptions.RemoveEmptyEntries); var warningList = (parts.Length > 1) ? parts[1] : null; FileInfo inputFile = new FileInfo(parts[0]); // Validation occurs in AddInputFile packageBuilder.AddFileWarningsToSuppress(inputFile, warningList); } } } // Validate the model if (!packageBuilder.ValidateModel()) { return(1); } // Save the package to disk packageBuilder.SaveToDisk(options.Output, new PackageOptions() { RefactorLogPath = options.RefactorLog?.FullName }); // Add predeployment and postdeployment scripts (must happen after SaveToDisk) packageBuilder.AddPreDeploymentScript(options.PreDeploy, options.Output); packageBuilder.AddPostDeploymentScript(options.PostDeploy, options.Output); return(0); }