rr-wfm / MSBuild.Sdk.SqlProj

An MSBuild SDK that provides similar functionality to SQL Server Data Tools (.sqlproj) projects
MIT License
380 stars 42 forks source link

Unrecognized command or argument '-p:UseSharedCompilation=false' when running on Github build #500

Closed popcatalin81 closed 4 months ago

popcatalin81 commented 5 months ago

Version : 2.6.1 I'm receiving this strange error when running on Github Actions runner on a new workflow. Strangely the same build works on an older workflow (with exact same parameters). The only difference is the slightly updated ubuntu-latest image the runner is using for one workflow but not the other. The error:

/home/runner/.nuget/packages/msbuild.sdk.sqlproj/2.6.1/Sdk/Sdk.targets(242,5): error MSB3073: The command "dotnet "/home/runner/.nuget/packages/msbuild.sdk.sqlproj/2.6.1/Sdk/../tools/net8.0/DacpacTool.dll" build -o "obj/Debug/*****Build.dacpac" -n "*****.Build" -v "1.0.0" -sv Sql140 -i "obj/Debug/***.InputFiles.txt"   -bp AllowSnapshotIsolation=True -dp IncludeCompositeObjects=true --predeploy ../*****/Script.PreDeployment.sql --postdeploy ../*****/Script.PostDeployment.sql --refactorlog ../*****/*****i.refactorlog      " exited with code 1. [/home/runner/work/*****/DB/Build/*****.Build.csproj]
  Using target framework net8.0 to run DacpacTool
  Unrecognized command or argument '-p:UseSharedCompilation=false'.
  Unrecognized command or argument '-p:EmitCompilerGeneratedFiles=true'.

For the life of me I can't figure out why this is happening. Any suggestions are welcome. Thank you.

jmezach commented 5 months ago

Interesting, haven't seen this before. What's even more interesting is that the output doesn't seem to suggest that those two arguments are being passed to the DacpacTool, yet that seems to be the complaint of the tool. Can you reproduce this on your local machine? Also do you have a diff you can share with the changes to the workflow? Maybe that will give us some points as to where to look for this issue.

ErikEJ commented 5 months ago

Can you share your .csproj?

popcatalin81 commented 5 months ago

This is the .csproj file

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="MSBuild.Sdk.SqlProj/2.6.1">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <OutputPath>..\[Redacted].Database.Admin\bin</OutputPath>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <SqlServerVersion>Sql140</SqlServerVersion>
    <AllowSnapshotIsolation>True</AllowSnapshotIsolation>
    <ReadCommittedSnapshot>True</ReadCommittedSnapshot>
    <ProduceReferenceAssembly>false</ProduceReferenceAssembly>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="..\[Redacted].Database.Admin\**\*.sql" Exclude="..\[Redacted].Database.Admin\bin\**;..\[Redacted].Database.Admin\obj\**;..\[Redacted].Database.Admin\Script.*;..\[Redacted].Database.Admin\SeedData\**" />
    <RefactorLog Include="..\[Redacted].Database.Admin\**\*.refactorlog" Exclude="..\[Redacted].Database.Admin\bin\**;..\[Redacted].Database.Admin\obj\**" />
    <None Include="..\[Redacted].Database.Admin\**\*.publish.xml" Exclude="..\[Redacted].Database.Admin\bin\**;..\[Redacted].Database.Admin\obj\**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Include="..\[Redacted].Database.Admin\**\*.sql" Exclude="..\[Redacted].Database.Admin\bin\**;..\[Redacted].Database.Admin\obj\**;..\[Redacted].Database.Admin\Script.*;"></None>
  </ItemGroup>
  <ItemGroup>
    <Content Remove="..\[Redacted].Database.Admin\dbo\Tables\Alert.sql" />
  </ItemGroup>
  <ItemGroup>
    <None Remove="..\[Redacted].Database.Admin\dbo\Tables\Alert.sql" />
  </ItemGroup>
  <ItemGroup>
    <PostDeploy Include="..\[Redacted].Database.Admin\Script.PostDeployment.sql" />
    <PreDeploy Include="..\[Redacted].Database.Admin\Script.PreDeployment.sql" />
  </ItemGroup>
</Project>
popcatalin81 commented 5 months ago

Interesting, haven't seen this before. What's even more interesting is that the output doesn't seem to suggest that those two arguments are being passed to the DacpacTool, yet that seems to be the complaint of the tool. Can you reproduce this on your local machine? Also do you have a diff you can share with the changes to the workflow? Maybe that will give us some points as to where to look for this issue.

No, sadly I cannot reproduce this on my local machine. The workflow actions are identical from one to another (copy paste) However the github runner decided to use slighly different images for the workflows:

This fails: image

And this one succeeds: image

Sadly there's no way to force one image version or another in GH actions.

ErikEJ commented 5 months ago

This is the spec for the two different images - cannot see any significant diff

2023.txt 2024.txt

popcatalin81 commented 5 months ago

For future reference:

Found the issue. The build is broken by the github/codeql-action/init@v3 Github's CodeQL code analysis engine. The action adds hooks to the C# compiler in order to determine what C# projects and code to analyze, however it injects some extra parameters in the build process that are passed to the DacpacTooltask (and other tasks as well). But DacpacTool does not support any extra unknown parameters and instead of ignoring them it just throws.

One point of improvement for the future might be for DacpacTool to have a switch to ignore unknown parameters during build.

ErikEJ commented 5 months ago

How do you mitigate the parsing issue?

popcatalin81 commented 5 months ago

How do you mitigate the parsing issue?

I've split the build into two sections, first one builds the Db projects. Then the CodeQL Init action is called, then the build builds the rest of the projects and finally the Code QL analyze action is called, which means the build hooks are not installed when the DB projects are initially built.

ErikEJ commented 5 months ago

@jmezach Wonder if this could be a solution: https://stackoverflow.com/a/76108416/183934