Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DacpacTool/ActualConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace MSBuild.Sdk.SqlProj.DacpacTool
{
public class ActualConsole : IConsole
{
public string ReadLine()
public string? ReadLine()
{
return Console.ReadLine();
}
Expand Down
38 changes: 19 additions & 19 deletions src/DacpacTool/BuildOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,52 @@ namespace MSBuild.Sdk.SqlProj.DacpacTool
public class BuildOptions : BaseOptions
{
[CliOption(Description = "Name of the package", Required = true, Name = "--name", Alias = "-n")]
public string Name { get; set; }
public required string Name { get; set; }

[CliOption(Description = "Version of the package", Required = false, Name = "--version", Alias = "-v")]
public string Version { get; set; }
public string? Version { get; set; }

[CliOption(Description = "Filename of the output package", Required = false, Name = "--output", Alias = "-o")]
public FileInfo Output { get; set; }
public FileInfo? Output { get; set; }

[CliOption(Description = "Target version of the model", Required = false, Name = "--sqlServerVersion", Alias = "-sv")]
public SqlServerVersion SqlServerVersion { get; set; } = SqlServerVersion.Sql170;

[CliOption(Description = "Text file listing all input files", Name = "--inputfile", Required = false, Alias = "-i")]
public FileInfo InputFile { get; set; }
public FileInfo? InputFile { get; set; }

[CliOption(Description = "Reference(s) to include", Required = false, Name = "--reference", Alias = "-r")]
public string[] Reference { get; set; }
public string[] Reference { get; set; } = [];

[CliOption(Description = "Build properties to be set on the model", Name = "--buildproperty", Required = false, Alias = "-bp")]
public string[] BuildProperty { get; set; }
public string[] BuildProperty { get; set; } = [];

[CliOption(Description = "Deploy properties to be set for the create script", Name = "--deployproperty", Required = false, Alias = "-dp")]
public string[] DeployProperty { get; set; }
public string[] DeployProperty { get; set; } = [];

[CliOption(Description = "SqlCmdVariable(s) to include", Name = "--sqlcmdvar", Required = false, Alias = "-sc")]
public string[] SqlCmdVar { get; set; }
public string[] SqlCmdVar { get; set; } = [];

[CliOption(Description = "Filename of optional pre-deployment script", Name = "--predeploy", Required = false)]
public FileInfo PreDeploy { get; set; }
public FileInfo? PreDeploy { get; set; }

[CliOption(Description = "Filename of optional pre-plan script", Name = "--preplan", Required = false)]
public FileInfo PrePlan { get; set; }
public FileInfo? PrePlan { get; set; }

[CliOption(Description = "Filename of optional post-deployment script", Name = "--postdeploy", Required = false)]
public FileInfo PostDeploy { get; set; }
public FileInfo? PostDeploy { get; set; }

[CliOption(Description = "Filename of optional refactor log script", Name = "--refactorlog", Required = false)]
public FileInfo RefactorLog { get; set; }
public FileInfo? RefactorLog { get; set; }

[CliOption(Description = "Run static code analysis", Name = "--runcodeanalysis", Required = false, Alias = "-an")]
public bool RunCodeAnalysis { get; set; }

[CliOption(Description = "List of rules to suppress in format '-Microsoft.Rules.Data.SR0001;-Microsoft.Rules.Data.SR0008'", Name = "--codeanalysisrules", Required = false, Alias = "-ar")]
public string CodeAnalysisRules { get; set; }
public string? CodeAnalysisRules { get; set; }

[CliOption(Description = "Custom code analysis rule assemblies to use", Name = "--codeanalysisassemblies", Required = false, Alias = "-aa")]
public FileInfo[] CodeAnalysisAssemblies { get; set; }
public FileInfo[] CodeAnalysisAssemblies { get; set; } = [];

[CliOption(Description = "Treat T-SQL Warnings As Errors", Name = "--warnaserror", Required = false)]
public bool WarnAsError { get; set; }
Expand All @@ -63,22 +63,22 @@ public class BuildOptions : BaseOptions
public bool GenerateCreateScript { get; set; }

[CliOption(Description = "Name of the database to use in the generated create script", Name = "--targetdatabasename", Required = false, Alias = "-tdn")]
public string TargetDatabaseName { get; set; }
public string? TargetDatabaseName { get; set; }

[CliOption(Description = "Warning(s) to suppress", Name = "--suppresswarnings", Required = false, Alias = "-spw")]
public string SuppressWarnings { get; set; }
public string? SuppressWarnings { get; set; }

[CliOption(Description = "Filename for warning(s) to suppress for particular files", Name = "--suppresswarningslistfile", Required = false, Alias = "-spl")]
public FileInfo SuppressWarningsListFile { get; set; }
public FileInfo? SuppressWarningsListFile { get; set; }

[CliOption(Description = "Generate ER diagram from the dacpac", Name = "--generateerdiagram", Required = false, Alias = "-ged")]
public bool GenerateErDiagram { get; set; }

[CliOption(Description = "JSON config file for ER diagram generation", Name = "--erdiagramconfig", Required = false, Alias = "-edc")]
public FileInfo[] ErDiagramConfig { get; set; }
public FileInfo[] ErDiagramConfig { get; set; } = [];

[CliOption(Description = "Optional ProjectGuid", Name = "--projectguid", Required = false, Alias = "-pg")]
public string ProjectGuid { get; set; }
public string? ProjectGuid { get; set; }

public async Task<int> RunAsync()
{
Expand Down
2 changes: 1 addition & 1 deletion src/DacpacTool/DacpacTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<Nullable>warnings</Nullable>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
14 changes: 7 additions & 7 deletions src/DacpacTool/DeployOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ internal sealed class DeployOptions : BaseOptions
#pragma warning restore CA1812 // Avoid uninstantiated internal classes
{
[CliOption(Description = "Path to the .dacpac package to deploy", Required = true, Name = "--input", Alias = "-i")]
public FileInfo Input { get; set; }
public required FileInfo Input { get; set; }

[CliOption(Description = "Name of the server to deploy the package to", Required = true, Name = "--targetServerName", Alias = "-tsn")]
public string TargetServerName { get; set; }
public required string TargetServerName { get; set; }

[CliOption(Description = "Port number to connect on (leave blank for default)", Name = "--targetPort", Required = false, Alias = "-tprt")]
public int? TargetPort { get; set; }

[CliOption(Description = "Name of the database to deploy the package to", Required = true, Name = "--targetDatabaseName", Alias = "-tdn")]
public string TargetDatabaseName { get; set; }
public required string TargetDatabaseName { get; set; }

[CliOption(Description = "Username used to connect to the target server, using SQL Server authentication", Required = false, Name = "--targetUser", Alias = "-tu")]
public string TargetUser { get; set; }
public string? TargetUser { get; set; }

[CliOption(Description = "Password used to connect to the target server, using SQL Server authentication", Required = false, Name = "--targetPassword", Alias = "-tp")]
public string TargetPassword { get; set; }
public string? TargetPassword { get; set; }

[CliOption(Description = "Properties used to control the deployment", Required = false, Name = "--property", Alias = "-p")]
public string[] Property { get; set; }
public string[] Property { get; set; } = [];

[CliOption(Description = "SqlCmdVariable(s) and their associated values, separated by an equals sign", Name = "--sqlcmdvar", Required = false, Alias = "-sc")]
public string[] SqlCmdVar { get; set; }
public string[] SqlCmdVar { get; set; } = [];

[CliOption(Description = "Whether to run pre- and postdeployment scripts from references", Name = "--runScriptsFromReferences", Required = false, Alias = "-sff")]
public bool RunScriptsFromReferences { get; set; }
Expand Down
41 changes: 21 additions & 20 deletions src/DacpacTool/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace MSBuild.Sdk.SqlProj.DacpacTool
public static class Extensions
#pragma warning restore CA1724 // Type names should not match namespaces
{
static Type CustomSchemaDataType;
static Type CustomSchemaDataType = null!;

static MethodInfo SetMetadataMethod;
static MethodInfo SetMetadataMethod = null!;
private static readonly Regex ExternalPartsRegex = new Regex(@"dbl=(?<dbl>\w+)|dbv=(?<dbv>\w+)|srv=(?<srv>\w+)",
RegexOptions.CultureInvariant | RegexOptions.Compiled, TimeSpan.FromSeconds(1));

Expand Down Expand Up @@ -49,7 +49,7 @@ static Extensions()
SetMetadataMethod = setMetadataMethod;
}

public static string Format(this BatchErrorEventArgs args, string source)
public static string Format(this BatchErrorEventArgs args, string? source)
{
ArgumentNullException.ThrowIfNull(args);

Expand Down Expand Up @@ -77,7 +77,7 @@ public static string Format(this BatchErrorEventArgs args, string source)
return outputMessageBuilder.ToString();
}

public static string Format(this BatchParserExecutionErrorEventArgs args, string source)
public static string Format(this BatchParserExecutionErrorEventArgs args, string? source)
{
ArgumentNullException.ThrowIfNull(args);

Expand Down Expand Up @@ -137,7 +137,7 @@ public static string Format(this DacModelException exception, string fileName)
return stringBuilder.ToString().Trim();
}

public static string GetPreDeploymentScript(this DacPackage package)
public static string? GetPreDeploymentScript(this DacPackage package)
{
ArgumentNullException.ThrowIfNull(package);

Expand All @@ -151,7 +151,7 @@ public static string GetPreDeploymentScript(this DacPackage package)
return streamReader.ReadToEnd();
}

public static string GetPrePlanScript(this DacPackage package)
public static string? GetPrePlanScript(this DacPackage package)
{
ArgumentNullException.ThrowIfNull(package);

Expand All @@ -165,7 +165,7 @@ public static string GetPrePlanScript(this DacPackage package)
return streamReader.ReadToEnd();
}

public static string GetPostDeploymentScript(this DacPackage package)
public static string? GetPostDeploymentScript(this DacPackage package)
{
ArgumentNullException.ThrowIfNull(package);

Expand All @@ -179,7 +179,7 @@ public static string GetPostDeploymentScript(this DacPackage package)
return streamReader.ReadToEnd();
}

public static void AddReference(this TSqlModel model, string referencePath, string externalParts, bool suppressErrorsForMissingDependencies)
public static void AddReference(this TSqlModel model, string referencePath, string? externalParts, bool suppressErrorsForMissingDependencies)
{
ArgumentNullException.ThrowIfNull(model);
ArgumentNullException.ThrowIfNull(referencePath);
Expand Down Expand Up @@ -212,16 +212,16 @@ public static void AddReference(this TSqlModel model, string referencePath, stri
AddCustomData(dataSchemaModel, customData);
}

private static string ParseExternalParts(string externalParts)
private static string? ParseExternalParts(string externalParts)
{
return ParseExternalParts(externalParts, ExternalPartsRegex);
}

private static string ParseExternalParts(string externalParts, Regex externalPartsRegex)
private static string? ParseExternalParts(string externalParts, Regex externalPartsRegex)
{
string serverVariableName = null;
string databaseVariableName = null;
string databaseVariableLiteralValue = null;
string? serverVariableName = null;
string? databaseVariableName = null;
string? databaseVariableLiteralValue = null;

// If there are '=' sign in argument assumes that this is formula, else assume that a single value passed and that it is database literal.
if (externalParts.Contains('=', StringComparison.Ordinal))
Expand Down Expand Up @@ -274,7 +274,7 @@ private static string ParseExternalParts(string externalParts, Regex externalPar
/// <summary>
/// Cached method info for FileUtils.EnsureIsDelimited
/// </summary>
private static MethodInfo _ensureIsDelimitedMethod;
private static MethodInfo? _ensureIsDelimitedMethod;
/// <summary>
/// This method found in Microsoft.Data.Tools.Utilities in class FileUtils. because of it is internal we do call through Reflection
/// </summary>
Expand All @@ -298,7 +298,7 @@ private static string EnsureIsDelimited(string name)
throw new InvalidOperationException("Unable to find EnsureIsDelimited method in Microsoft.Data.Tools.Utilities assembly.");
}

return (string)_ensureIsDelimitedMethod.Invoke(null, new object[]{ name });
return (string)_ensureIsDelimitedMethod.Invoke(null, new object[]{ name })!;
}

public static IEnumerable<string> GetReferencedDacPackages(this TSqlModel model)
Expand All @@ -315,14 +315,14 @@ public static IEnumerable<string> GetReferencedDacPackages(this TSqlModel model)
throw new InvalidOperationException("Unable to find GetCustomData method on DataSchemaModel.");
}

var references = (IEnumerable) getCustomDataMethod.Invoke(dataSchemaModel, new object[] { "Reference", "SqlSchema" });
var references = (IEnumerable?) getCustomDataMethod.Invoke(dataSchemaModel, new object[] { "Reference", "SqlSchema" });

if (references == null)
{
return result;
}

MethodInfo getMetadataMethod = null;
MethodInfo? getMetadataMethod = null;
foreach (var reference in references)
{
if (getMetadataMethod == null)
Expand All @@ -335,7 +335,7 @@ public static IEnumerable<string> GetReferencedDacPackages(this TSqlModel model)
throw new InvalidOperationException("Unable to find GetMetadata method on reference.");
}

var fileName = (string)getMetadataMethod.Invoke(reference, new object[] { "FileName" });
var fileName = (string?)getMetadataMethod.Invoke(reference, new object[] { "FileName" });
if (!string.IsNullOrEmpty(fileName))
{
result.Add(fileName);
Expand Down Expand Up @@ -408,7 +408,7 @@ public static IEnumerable<ModelValidationError> GetModelValidationErrors(this TS
}

var result = new List<ModelValidationError>();
PropertyInfo documentProperty = null;
PropertyInfo? documentProperty = null;
foreach (var modelValidationError in modelValidationErrors)
{
if (documentProperty == null)
Expand All @@ -421,7 +421,8 @@ public static IEnumerable<ModelValidationError> GetModelValidationErrors(this TS
throw new InvalidOperationException("Unable to find Document property on model validation error.");
}

var dacModelError = createDacModelErrorMethod.Invoke(service, new[] { modelValidationError }) as DacModelError;
var dacModelError = createDacModelErrorMethod.Invoke(service, new[] { modelValidationError }) as DacModelError
?? throw new InvalidOperationException("Unable to create DacModelError for model validation error.");
result.Add(new ModelValidationError(dacModelError, documentProperty.GetValue(modelValidationError) as string));
}

Expand Down
2 changes: 1 addition & 1 deletion src/DacpacTool/IConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ namespace MSBuild.Sdk.SqlProj.DacpacTool
public interface IConsole
{
void WriteLine(string value);
string ReadLine();
string? ReadLine();
}
}
6 changes: 3 additions & 3 deletions src/DacpacTool/InspectOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace MSBuild.Sdk.SqlProj.DacpacTool
public class InspectOptions : BaseOptions
{
[CliOption(Description = "Filename of optional pre-deployment script", Name = "--predeploy", Required = false)]
public FileInfo PreDeploy { get; set; }
public FileInfo? PreDeploy { get; set; }

[CliOption(Description = "Filename of optional pre-plan script", Name = "--preplan", Required = false)]
public FileInfo PrePlan { get; set; }
public FileInfo? PrePlan { get; set; }

[CliOption(Description = "Filename of optional post-deployment script", Name = "--postdeploy", Required = false)]
public FileInfo PostDeploy { get; set; }
public FileInfo? PostDeploy { get; set; }

public int Run()
{
Expand Down
2 changes: 1 addition & 1 deletion src/DacpacTool/ModelValidationError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ModelValidationError
private readonly int _errorCode;
private readonly string _message;

public ModelValidationError(DacModelError modelError, string sourceName)
public ModelValidationError(DacModelError modelError, string? sourceName)
{
modelError = modelError ?? throw new ArgumentNullException(nameof(modelError));
_sourceName = string.IsNullOrEmpty(sourceName) ?
Expand Down
4 changes: 2 additions & 2 deletions src/DacpacTool/PackageAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class PackageAnalyzer
private readonly Dictionary<string, HashSet<string>> _suppressedProblemsByRule = new(StringComparer.Ordinal);
private readonly char[] separator = new[] { ';' };

public PackageAnalyzer(IConsole console, string rulesExpression)
public PackageAnalyzer(IConsole console, string? rulesExpression)
{
_console = console ?? throw new ArgumentNullException(nameof(console));

Expand Down Expand Up @@ -103,7 +103,7 @@ public void Analyze(TSqlModel model, FileInfo outputFile, FileInfo[] analyzers)
#pragma warning restore CA1031 // Do not catch general exception types
}

private void BuildRuleLists(string rulesExpression)
private void BuildRuleLists(string? rulesExpression)
{
if (!string.IsNullOrWhiteSpace(rulesExpression))
{
Expand Down
Loading
Loading