DacFx
DacFx copied to clipboard
error MSB4020: The value "" of the "Project" attribute in element <Import> is invalid with version 0.1.15-preview
- SqlPackage or DacFx Version: 162.2.111.2
- .NET Framework (Windows-only) or .NET Core: 6.0
- Environment (local platform and source/target platforms): Codespaces
Steps to Reproduce:
- Create a new project:
dotnet new sqlproj -n "devDB2" -tp "SqlAzureV12"
- Add a table
- Build the project
Did this occur in prior versions? If not - which version(s) did it work in?
No, up until version 0.1.14-preview it was working correctly
can you share the sql for the table you add?
I don't repro it yet with:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build">
<Sdk Name="Microsoft.Build.Sql" Version="0.1.15-preview" />
<PropertyGroup>
<Name>devDB2</Name>
<DSP>Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider</DSP>
<ModelCollation>1033, CI</ModelCollation>
</PropertyGroup>
</Project>
CREATE TABLE dbo.sometable (
id INT IDENTITY(1,1) PRIMARY KEY,
name NVARCHAR(100) NOT NULL
);
(used dotnet new as above to get there)
building with dotnet build
The only new Import we added in 0.1.15-preview is to Microsoft.NET.Sdk.targets, which shouldn't be empty either https://github.com/microsoft/DacFx/blame/a888164f1e83f0b64f130875600d90205adb7c23/src/Microsoft.Build.Sql/sdk/Sdk.targets#L50
Sure. I installed the SqlPackage and the project template using the following:
dotnet tool install -g microsoft.sqlpackage
dotnet new install Microsoft.Build.Sql.Templates
then I create a new database project via
dotnet new sqlproj -n "devDB2" -tp "SqlAzureV12"
and then I add a new table using VS Code Database Project extension that gets installed in the devcontainer automatically:
Initializing SQL tools service for the mssql extension.
Note: mssql commands will be available after installing the service.
Platform: linux, x86_64, name=debian, version=12 (Debian)
Installing SQL tools service to /home/vscode/.vscode-server/extensions/ms-mssql.mssql-1.22.1/sqltoolsservice/4.10.2.1/Debian.
Downloading https://github.com/Microsoft/sqltoolsservice/releases/download/4.10.2.1/microsoft.sqltools.servicelayer-rhel-x64-net7.0.tar.gz
(70015 KB) .................... Done!
Installing ...
Done! 853 files unpacked.
I add the following table:
CREATE TABLE [dbo].[person] (
[person_id] INT IDENTITY (1, 1) NOT NULL PRIMARY KEY CLUSTERED ([person_id] ASC),
[person_name] NVARCHAR (200) NOT NULL,
[person_email] NVARCHAR (200) NOT NULL,
[pet_preference] NVARCHAR (100) NOT NULL
);
and then if I try to build (from VS Code) I get the followin output
[ Build ]
> "/usr/share/dotnet/dotnet" build "/workspaces/azure-sql-db-developers-workshop/database/devDB2/devDB2.sqlproj" /p:NetCoreBuild=true /p:SystemDacpacsLocation="/home/vscode/.vscode-server/extensions/ms-mssql.sql-database-projects-vscode-1.4.1/BuildDirectory"
stdout: MSBuild version 17.7.4+3ebbd7c49 for .NET
stdout:
stdout: Determining projects to restore...
stdout:
stdout: Restored /workspaces/azure-sql-db-developers-workshop/database/devDB2/devDB2.sqlproj (in 2.48 sec).
stdout:
stdout: /usr/share/dotnet/sdk/7.0.406/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1199,3): error MSB4020: The value "" of the "Project" attribute in element <Import> is invalid. [/workspaces/azure-sql-db-developers-workshop/database/devDB2/devDB2.sqlproj]
stdout:
stdout:
stdout: Build FAILED.
stdout:
stdout:
stdout: /usr/share/dotnet/sdk/7.0.406/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1199,3): error MSB4020: The value "" of the "Project" attribute in element <Import> is invalid. [/workspaces/azure-sql-db-developers-workshop/database/devDB2/devDB2.sqlproj]
stdout: 0 Warning(s)
stdout: 1 Error(s)
stdout:
stdout: Time Elapsed 00:00:09.44
stdout:
>>> "/usr/share/dotnet/dotnet" build "/workspaces/azure-sql-db-developers-workshop/database/devDB2/devDB2.sqlproj" /p:NetCoreBuild=true /p:SystemDacpacsLocation="/home/vscode/.vscode-server/extensions/ms-mssql.sql-database-projects-vscode-1.4.1/BuildDirectory" … exited with code: 1
>>> "/usr/share/dotnet/dotnet" build "/workspaces/azure-sql-db-developers-workshop/database/devDB2/devDB2.sqlproj" /p:NetCoreBuild=true /p:SystemDacpacsLocation="/home/vscode/.vscode-server/extensions/ms-mssql.sql-database-projects-vscode-1.4.1/BuildDirectory" … errored out: Process exited with code 1
If I manually change the .sqlprj file to use version "0.1.14-preview" then the build works as expected.
I tried to use the table that you created @dzsquared, and I get the same error.
Btw, opening the targets
files, it shows that the error is raised at this line:
<Import Project="$(ILLinkTargetsPath)" Condition="'$(Language)' != 'C++'" />
I believe this exact error is fixed by https://github.com/dotnet/sdk/pull/30091
That property ILLinkTargetsPath
should be set during restore, but in some cases it seems to leave it blank. The fix above safeguards against that. I suggest updating to latest .NET 8 SDK to get that fix.
@zijchen @yorek I wonder if this was fixed in any .net 6 patch releases. if not, we've effectively found ourselves a known issue with .net 6 support
That target was introduced in .NET 7 so it's not in the .NET 6 SDK, but the fix isn't in the latest .NET 7 patch.
Yes, I have both .NET 6 and 7 installed, but the build process uses the msbuild tool shipped with .NET 7 SDK. Any idea how to fix this without having to download .NET 8?
Does running an explicit dotnet restore
before build solve the issue? I'm not sure if there is any fix besides asking the dotnet team to port the change to .net 7 sdk
I'll use the workaround to avoid installing 0.1.15-preview projects for now.
Do you know there is the need to add a reference to Microsoft.NET.Sdk.targets in the Microsoft.Build.Sql project? I mean, in 0.1.14 it was not there and everything was working. Is 0.1.15 using something that require the Microsoft.NET.Sdk target?
It is to support transitive project references for sqlproj. If A references B and B references C, A should now understand C's objects.