-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to build in VS - Visual Studio support for Microsoft.Build.Sql #180
Comments
@ErikEJ can you even build the project in VS? even with the 4 lines you mentioned, I get full project contents:
|
@Real-JD-UK you are not using the latest SDK version |
Hi @ErikEJ , can you be more specific on how you create the project and where you are trying to build it? I have created a sample SDK style project on Azure Data Studio (1.40.0) and was able to build it in ADS. Are you trying to open the project in the Visual Studio? If so, the SDK style project is not supported in VS yet! (Edited: typo - isn't supported) With the project I was able to build "dotnet build "path/sampleproj.sqlproj" /p:NetCoreBuild=true", but msbuild is failing with "our project does not reference ".NETFramework,Version=v4.8" framework"! is this what you are referring about? |
Yes, as the title of the issue states this is about building in VS. Its all fine that you can build in limited cross platform tooling but the circle is not complete until you can build in VS and get the intellisense and table editing experience. |
I had a typo in my previous comment and edited. We do have a future enhancement for the VS to support SDK style projects and will support that in future. |
Support for Microsoft.Build.Sql sqlprojects is planned for future Visual Studio (SSDT) releases. Reopening this item until it is shipped |
I had a similar issue, and I was able to resolve this by deleting the obj folder for my project. And so, I set up the project to clean the project and to delete the obj folder before clean. It's still a work in progress, but I landed on the code below to both build in Visual Studio 2022 and via the dotnet cli. The dotnet cli seems to build just fine without deleting the obj folder, but it wasn't deleting the folder, so I just added ContinueOnError="True". Edited code since Visual Studio 2022 didn't seem to output the dacpac.
|
For those with Visual Studio issues? Are your files loading properly in Visual Studio? Also, if I have a .sql file in my output directory (which I am setting as a custom path in the project file, e.g. .\sql</OutputPath>), it won't load the project. Has anyone seen this issue? |
When I try to build in visual studio after building in AzureDataSudio I get this error: If I delete the project.assets.json file from the obj folder then it will build fine. Found there is this already: But it doesn't work for me had to switch to: I used just $(ProjectDir) to start with - this builds in visual studio but failed more often than not in Using the SolutionDir instead makes the path *Undefined* in AzureDataStudio |
When will have support for SDK-style projects in Visual Studio? It seems like an easy-to-do feature that would be very useful for many of us, but seems to be delayed for more than a year already. |
With the new version, "0.1.15-preview", I can no longer build from the command line if I have the fix that CSharpFiasco posted above to build from Visual Studio. However, if I don't have that fix, I still can't build from Visual Studio. |
Sharing what my customized .sqproj file ended up being for others who come across this thread while trying to troubleshoot new use of this project sdk: <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build">
<Sdk Name="Microsoft.Build.Sql" Version="0.1.15-preview" />
<PropertyGroup>
<Name>YourProjectName</Name>
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql160DatabaseSchemaProvider</DSP>
<ModelCollation>1033, CI</ModelCollation>
<ProjectGuid>{your-project-guild}</ProjectGuid>
<TargetDatabaseSet>True</TargetDatabaseSet>
<!--
The sdk will target netstandard2.1 automatically when doing a dotnet cli build but we need to target
netframework when the msbuild type is full (a.k.a. building from within Visual Studio) until the Visual Studio
SSDT extension supports the new sql project SDK.
-->
<TargetFrameworkVersion Condition="'$(MSBuildRuntimeType)' != 'Core'">v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile Condition="'$(MSBuildRuntimeType)' != 'Core'" />
</PropertyGroup>
<!--
NOTE: The sql project sdk automatically includes a default globbing pattern for sql files but we still need them to be listed
explicitly for VisualStudio SSDT to display them
See: https://github.com/microsoft/DacFx/blob/main/src/Microsoft.Build.Sql/docs/Converting-Existing.md#default-sql-files-included-in-build
See: https://github.com/microsoft/DacFx/blob/a888164f1e83f0b64f130875600d90205adb7c23/src/Microsoft.Build.Sql/sdk/Sdk.props#L35
-->
<ItemGroup>
<Build Include="**/*.sql" />
<Build Remove="bin/**/*.sql" />
<Build Remove="obj/**/*.sql" />
<!-- Also Build Remove any .sql file patterns you want to exclude e.g. -->
<Build Remove="StaticDataScriptsReferencedInPostDeploy/**/*.sql" />
<!-- Explicitly include your folders so that VisualStudio SSDT will display your files -->
<Folder Include="OtherFolder" />
<Folder Include="StaticDataScriptsReferencedInPostDeploy" />
<Folder Include="Tables" />
<None Include="README.md" />
<None Include="StaticDataScriptsReferencedInPostDeploy/**/*.sql" />
</ItemGroup>
<ItemGroup>
<PostDeploy Include="Script.PostDeployment.sql" />
</ItemGroup>
<!--
Building through visual studio (targeting net48) will fail if a previous build through the dotnet core cli
has run and created the obj/project.assets.json file. This custom target should delete
the file before the visual studio build starts.
-->
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(MSBuildRuntimeType)' != 'Core'">
<Message Importance="high" Text="Ensuring the $(MSBuildThisFileDirectory)\obj\project.assets.json file is removed, if necessary, so that the database project can be built through VisualStudio SSDT without errors" />
<Delete Files="$(MSBuildThisFileDirectory)\obj\project.assets.json" />
</Target>
</Project> |
@RyanThomas73 Thanks for sharing! |
This seems super weird that there's a Convert Existing doc that completely fails to mention that NONE of this works in Visual Studio, which is pretty much the only place most people deal with their existing .sqlproj's as far as I'm aware. Yes, I'm aware some of the docs ONLY mention ADS / VSCode, but this should still be called out explicitly as "you will need to remove your .sqlproj from your Visual Studio solution and manage it with one of these two tools instead, until the SSDT team....... or use these workarounds from this issue thread, where [....] will not work" or something. I did a bunch of reading on this before actually taking on the conversion and none of it prepared me for how much this breaks the visual studio flow. I had a bunch of hacks in my old .sqlproj all for building from CLI, and removed them all on the basis of the convert existing guidelines saying to. In the end, seems like I need to add a bunch of hacks in the other direction now to keep it functional in in a VS .NET 8 project where it worked fine before with the old hacks. I get it if the VS team needs to a do a bunch of stuff of their own to support the new SDK, but at least call that out in the 'convert-existing' doc, with some links to these workarounds for all the people that have existing projects where they're obviously using SSDT in VS. Will the VS SSDT updates happen before this gets out of -preview? Or is that not on any official roadmap? |
@EklipZgit That being said, the .md doc could benefit from that callout about using it in conjunction with SSDT
|
Tried 1.19-preview with vs2022 17.10.1 get (d If I try passing "/p:NetCoreBuild=true" to get around, get this isntead C:\Users\cmire.nuget\packages\microsoft.build.sql\0.1.19-preview\Sdk\Sdk.targets(52,3): error MSB4019: The imported project "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.DefaultAssemblyInfo.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\Microsoft Visual Studio\20 |
Working example for 1.19-preview with vs2022 17.10.2 (Community Edition) <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build">
<Sdk Name="Microsoft.Build.Sql" Version="0.1.19-preview" />
<PropertyGroup>
<Name>MySample</Name>
<ProjectGuid>{71b1081a-ce12-4fc4-9c9c-53bf630fc0d7}</ProjectGuid>
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql160DatabaseSchemaProvider</DSP>
<ModelCollation>1033, CI</ModelCollation>
<TargetDatabaseSet>True</TargetDatabaseSet>
</PropertyGroup>
<Target Name="BeforeBuild">
<Delete Files="$(BaseIntermediateOutputPath)\project.assets.json" />
</Target>
<!--
Support Visual Studio.
Solution is a mix of example from @RyanThomas73, and a recent commit to DaxFx with support for Visual Studio:
* https://github.com/microsoft/DacFx/issues/180#issuecomment-2010033767
* https://github.com/microsoft/DacFx/commit/3cd56f7c173457ed52e76979dddf901e7285f090
-->
<!-- building in Visual Studio requires some sort of TargetFrameworkVersion. So we condition to NetCoreBuild as false to avoid failures -->
<PropertyGroup Condition="'$(MSBuildRuntimeType)' != 'Core'">
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkMoniker>.NETFramework,Version=$(TargetFrameworkVersion)</TargetFrameworkMoniker>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
</PropertyGroup>
<ItemGroup Condition="'$(MSBuildRuntimeType)' != 'Core'">
<!-- Build default globbing pattern includes all sql files in all subfolders, excluding bin and obj, visual studio is likely to mess with this... -->
<Build Include="**/*.sql" />
<Build Remove="bin/**/*.sql" />
<Build Remove="obj/**/*.sql" />
</ItemGroup>
<ItemGroup>
<Folder Include="Stored Procedures\" />
<Folder Include="Tables\" />
</ItemGroup>
<!--
Building through visual studio will fail with `Your project does not reference ".NETFramework,Version=v4.7.2" framework.` if a previous build through the dotnet core cli
has run and created the obj/project.assets.json file. This custom target will delete the file before the visual studio build starts.
-->
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(MSBuildRuntimeType)' != 'Core'">
<Message Importance="high" Text="Ensuring the $(MSBuildThisFileDirectory)\obj\project.assets.json file is removed, if necessary, so that the database project can be built through VisualStudio SSDT without errors" />
<Delete Files="$(MSBuildThisFileDirectory)\obj\project.assets.json" />
</Target>
</Project> |
While this has been an interesting exercise, Visual Studio still lacks nuget package support so guess I'm stuck waiting for an official release :-( |
Preview support for the Microsoft.Build.Sql SDK is landing in Visual Studio soon - will update ya'll as soon as the first release goes out the door! |
With Visual Studio 17.12 preview 2 - support for Microsoft.Build.Sql SDK-style projects is now available in preview for Visual Studio. 2 key limitations to note:
|
@dzsquared already?? 😉 - this is amazing! |
it seems like just yesterday 0.1.1-alpha was released..... but according to my notes - https://www.nuget.org/packages/Microsoft.Build.Sql/0.1.1-alpha - it was almost 3 years ago 😄 |
Steps to Reproduce:
The text was updated successfully, but these errors were encountered: