Skip to content

Commit

Permalink
Use an intermediate file containing each object definition (#56)
Browse files Browse the repository at this point in the history
* Use an intermediate file containing each object definition, instead of passing each object file in the CLI command

Resolves #43

* Remove deprecated --input option

* Resolve PR feedback

Co-authored-by: Rosenberg, Jeff <[email protected]>
  • Loading branch information
2 people authored and jmezach committed Sep 8, 2020
1 parent a3a0447 commit 58da6c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/DacpacTool/BuildOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class BuildOptions
public string Version { get; set; }
public FileInfo Output { get; set; }
public SqlServerVersion SqlServerVersion { get; set; }
public FileInfo[] Input { get; set; }
public FileInfo InputFile { get; set; }
public string[] Reference { get; set; }
public string[] Property { get; set; }
public string[] SqlCmdVar { get; set; }
Expand Down
18 changes: 13 additions & 5 deletions src/DacpacTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static async Task<int> Main(string[] args)
new Option<string>(new string[] { "--version", "-v" }, "Version of the package"),
new Option<FileInfo>(new string[] { "--output", "-o" }, "Filename of the output package"),
new Option<SqlServerVersion>(new string[] { "--sqlServerVersion", "-sv" }, () => SqlServerVersion.Sql150, description: "Target version of the model"),
new Option<FileInfo[]>(new string[] { "--input", "-i" }, "Input file name(s)"),
new Option<FileInfo>(new string[] { "--inputfile", "-i" }, "Text file listing all input files"),
new Option<string[]>(new string[] { "--reference", "-r" }, "Reference(s) to include"),
new Option<FileInfo>(new string[] { "--predeploy" }, "Filename of optional pre-deployment script"),
new Option<FileInfo>(new string[] { "--postdeploy" }, "Filename of optional post-deployment script"),
Expand Down Expand Up @@ -88,12 +88,20 @@ private static int BuildDacpac(BuildOptions options)
packageBuilder.AddSqlCmdVariables(options.SqlCmdVar);
}

// Add input files
if (options.Input != null)
// Add input files by iterating through $Project.InputFiles.txt
if (options.InputFile != null)
{
foreach (var inputFile in options.Input)
if (options.InputFile.Exists)
{
packageBuilder.AddInputFile(inputFile);
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}");
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,19 @@
</PropertyNames>
<IncludedDacpacReferenceFiles Include="@(DacpacReference->'%(DacpacFile)')" />
</ItemGroup>
<!-- Write the list of input files to a file to be consumed by the dacpac tool -->
<Message Importance="Low" Text="Writing input files to $(IntermediateOutputPath)$(MSBuildProjectName).InputFiles.txt" />
<WriteLinesToFile
File="$(IntermediateOutputPath)$(MSBuildProjectName).InputFiles.txt"
Overwrite="true"
Lines="@(Content)" />
<!-- Build arguments for the command line tool -->
<PropertyGroup>
<OutputPathArgument>@(IntermediateAssembly->'-o &quot;%(Identity)&quot;', ' ')</OutputPathArgument>
<MetadataArguments>-n &quot;$(MSBuildProjectName)&quot; -v &quot;$(PackageVersion)&quot;</MetadataArguments>
<SqlServerVersionArgument>-sv $(SqlServerVersion)</SqlServerVersionArgument>
<ReferenceArguments>@(DacpacReference->'-r &quot;%(DacpacFile);%(DatabaseVariableLiteralValue)&quot;', ' ')</ReferenceArguments>
<InputFileArguments>@(Content->'-i &quot;%(FullPath)&quot;', ' ')</InputFileArguments>
<InputFileArguments>-i &quot;$(IntermediateOutputPath)$(MSBuildProjectName).InputFiles.txt&quot;</InputFileArguments>
<PropertyArguments>@(PropertyNames->'-p %(Identity)=%(PropertyValue)', ' ')</PropertyArguments>
<SqlCmdVariableArguments>@(SqlCmdVariable->'-sc %(Identity)', ' ')</SqlCmdVariableArguments>
<PreDeploymentScriptArgument>@(PreDeploy->'--predeploy %(Identity)', ' ')</PreDeploymentScriptArgument>
Expand Down

0 comments on commit 58da6c3

Please sign in to comment.