MSBuild.Sdk.SqlProj: :r relative path not working on linux

Version: MSBuild.Sdk.SqlProj/1.11.1

We’re using mcr.microsoft.com/dotnet/core/sdk:3.1-buster on our docker-based build.

Expectation: :r scripts in a relative path should be included and and run in the post-deploy script.

Actual: Error - file not found.

Detail: The container is Debian 10 based - Linux.

When running dotnet build on there for the dacpac project, we have an issue with paths.

We have our data insertions separated into scripts files under a data folder. These are then included in the post-build script as:

:r .\Data\InsertScript1.sql
:r .\Data\InsertScript2.sql

But when we run the build from a Dockerfile, we get the following output:

Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /src/DB.build.csproj (in 222 ms).
  Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
   ---> System.IO.FileNotFoundException: Could not find file '/src/.\Data\InsertScript1.sql'.
  File name: '/src/.\Data\InsertScript1.sql'
     at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
     at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
     at System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
     at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
     at System.IO.StreamReader..ctor(String path)
     at MSBuild.Sdk.SqlProj.DacpacTool.ScriptParser.Microsoft.SqlTools.ServiceLayer.BatchParser.ICommandHandler.Include(TextBlock includeBlock, TextReader& stream, String& newFilename) in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/src/DacpacTool/ScriptParser.cs:line 64
     at Microsoft.SqlTools.ServiceLayer.BatchParser.Parser.ParseInclude() in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/sqltoolsservice/src/Microsoft.SqlTools.ManagedBatchParser/BatchParser/Parser.cs:line 302
     at Microsoft.SqlTools.ServiceLayer.BatchParser.Parser.ParseLines() in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/sqltoolsservice/src/Microsoft.SqlTools.ManagedBatchParser/BatchParser/Parser.cs:line 394
     at Microsoft.SqlTools.ServiceLayer.BatchParser.Parser.Parse() in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/sqltoolsservice/src/Microsoft.SqlTools.ManagedBatchParser/BatchParser/Parser.cs:line 233
     at MSBuild.Sdk.SqlProj.DacpacTool.ScriptParser.Parse() in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/src/DacpacTool/ScriptParser.cs:line 28
     at MSBuild.Sdk.SqlProj.DacpacTool.ScriptParser.CollectFileNames() in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/src/DacpacTool/ScriptParser.cs:line 35
     at MSBuild.Sdk.SqlProj.DacpacTool.ScriptInspector.AddIncludedFiles(FileInfo file) in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/src/DacpacTool/ScriptInspector.cs:line 28
     at MSBuild.Sdk.SqlProj.DacpacTool.Program.InspectIncludes(InspectOptions options) in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/src/DacpacTool/Program.cs:line 149
     --- End of inner exception stack trace ---
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at System.Delegate.DynamicInvokeImpl(Object[] args)
     at System.Delegate.DynamicInvoke(Object[] args)
     at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
     at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__21_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseVersionOption>b__0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseTypoCorrections>b__0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__22_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__20_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()
/root/.nuget/packages/msbuild.sdk.sqlproj/1.11.1/Sdk/Sdk.targets(151,5): error MSB3073: The command "dotnet "/root/.nuget/packages/msbuild.sdk.sqlproj/1.11.1/Sdk/../tools/netcoreapp3.1/DacpacTool.dll" collect-includes --predeploy Script.PreDeployment.sql --postdeploy Script.PostDeployment.sql " exited with code 1. [/src/DB.build.csproj]

Changing the paths to ./ in the SQL file gives an “Incorrect syntax near :” error.

As a workaround we’ve moved our scripts to be in the same folder as the post build script.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 18 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@BjBlazkowicz Yes, that’s indeed what’s required and what I believe is documented in the README.md as well but if you feel there’s room for improvement there please let us know. Do note that by default we exclude the Pre-Deployment and Post-Deployment folders as noted in the README so you could rename PostDeploy to Post-Deployment so you don’t have to make changes to your project file.

@PyroSA It is my current understanding that your issues is resolved so I’m going to go ahead and close this issue, but feel free to re-open if that is not the case.