Skip to content

Commit 3c5615d

Browse files
authored
Update readme for 3.1.0 (#706)
add SQL CLR section fixes #109
1 parent eaf890e commit 3c5615d

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

README.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dotnet new sqlproj -s Sql130
4545
You should now have a project file with the following contents:
4646

4747
```xml
48-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
48+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
4949
<PropertyGroup>
5050
<TargetFramework>netstandard2.1</TargetFramework>
5151
<SqlServerVersion>Sql150</SqlServerVersion>
@@ -132,7 +132,7 @@ If you already have a SSDT (.sqlproj) project in your solution, you can keep tha
132132
There are a lot of properties that can be set on the model in the resulting `.dacpac` file which can be influenced by setting those properties in the project file using the same name. For example, the snippet below sets the `RecoveryMode` property to `Simple`:
133133

134134
```xml
135-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
135+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
136136
<PropertyGroup>
137137
<TargetFramework>netstandard2.1</TargetFramework>
138138
<RecoveryMode>Simple</RecoveryMode>
@@ -151,7 +151,7 @@ Like `.sqlproj` projects `MSBuild.Sdk.SqlProj` supports controlling T-SQL build
151151
Treating warnings as errors can be optionally enabled by adding a property `TreatTSqlWarningsAsErrors` to the project file:
152152

153153
```xml
154-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
154+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
155155
<PropertyGroup>
156156
<TreatTSqlWarningsAsErrors>True</TreatTSqlWarningsAsErrors>
157157
...
@@ -164,7 +164,7 @@ Treating warnings as errors can be optionally enabled by adding a property `Trea
164164
To suppress specific warnings from being treated as errors, add a comma-separated list of warning codes to `SuppressTSqlWarnings` property in the project file:
165165

166166
```xml
167-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
167+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
168168
<PropertyGroup>
169169
<SuppressTSqlWarnings>71558,71502</SuppressTSqlWarnings>
170170
<TreatTSqlWarningsAsErrors>True</TreatTSqlWarningsAsErrors>
@@ -176,7 +176,7 @@ To suppress specific warnings from being treated as errors, add a comma-separate
176176
You can suppress warnings for a specific file by adding `SuppressTSqlWarnings` for this file:
177177

178178
```xml
179-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
179+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
180180
<PropertyGroup>
181181
...
182182
</PropertyGroup>
@@ -197,7 +197,7 @@ You can suppress warnings for a specific file by adding `SuppressTSqlWarnings` f
197197
To include these scripts into your `.dacpac` add the following to your `.csproj`:
198198

199199
```xml
200-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
200+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
201201
<PropertyGroup>
202202
...
203203
</PropertyGroup>
@@ -214,7 +214,7 @@ It is important to note that scripts in the `Pre-Deployment` and `Post-Deploymen
214214
By default the pre- and/or post-deployment script of referenced packages (both [PackageReference](#package-references) and [ProjectReference](#project-references)) are not run when using `dotnet publish`. This can be optionally enabled by adding a property `RunScriptsFromReferences` to the project file as in the below example:
215215

216216
```xml
217-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
217+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
218218
<PropertyGroup>
219219
<RunScriptsFromReferences>True</RunScriptsFromReferences>
220220
...
@@ -231,7 +231,7 @@ By default the pre- and/or post-deployment script of referenced packages (both [
231231
Especially when using pre- and post-deployment scripts, but also in other scenario's, it might be useful to define variables that can be controlled at deployment time. This is supported using SQLCMD variables. These variables can be defined in your project file using the following syntax:
232232

233233
```xml
234-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
234+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
235235
<PropertyGroup>
236236
...
237237
</PropertyGroup>
@@ -256,7 +256,7 @@ Especially when using pre- and post-deployment scripts, but also in other scenar
256256
`MSBuild.Sdk.SqlProj` supports referencing NuGet packages that contain `.dacpac` packages. These can be referenced by using the `PackageReference` format familiar to .NET developers. They can also be installed through the NuGet Package Manager in Visual Studio.
257257

258258
```xml
259-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
259+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
260260
<PropertyGroup>
261261
<TargetFramework>netstandard2.1</TargetFramework>
262262
</PropertyGroup>
@@ -270,7 +270,7 @@ Especially when using pre- and post-deployment scripts, but also in other scenar
270270
It will assume that the `.dacpac` file is inside the `tools` folder of the referenced package and that it has the same name as the NuGet package. Referenced packages that do not adhere to this convention will be silently ignored. However, you have the ability to override this convention by using the `DacpacName` attribute on the `PackageReference` (introduced in version 2.5.0). For example:
271271

272272
```xml
273-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
273+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
274274
<PropertyGroup>
275275
<TargetFramework>netstandard2.1</TargetFramework>
276276
<SqlServerVersion>Sql160</SqlServerVersion>
@@ -287,7 +287,7 @@ This will add a reference to the `tools\SomeOtherDacpac.dacpac` file inside the
287287
By default, the package reference is treated as being part of the same database. For example, if the reference package contains a `.dacpac` that has a table and a stored procedure and you would `dotnet publish` the project the table and stored procedure from that package will be deployed along with the contents of your project to the same database. If this is not desired, you can add the `DatabaseVariableLiteralValue` item metadata to the `PackageReference` specifying a different database name:
288288

289289
```xml
290-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
290+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
291291
<PropertyGroup>
292292
<TargetFramework>netstandard2.1</TargetFramework>
293293
</PropertyGroup>
@@ -304,7 +304,7 @@ You can also use SQLCMD variables to set references, similar to the behavior of
304304
>Note: Don't forget to define appropriate [SQLCMD variables](#sqlcmd-variables)
305305
306306
```xml
307-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
307+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
308308
<PropertyGroup>
309309
<TargetFramework>netstandard2.1</TargetFramework>
310310
</PropertyGroup>
@@ -347,7 +347,7 @@ sqlpackage
347347
Microsoft has released NuGet packages containing the definitions of the `master` and `msdb` databases. This is useful if you want to reference objects from those databases within your own projects without getting warnings. To reference these, you'll need to use at least version 2.5.0 of MSBuild.Sdk.SqlProj as you'll need to use the `DacpacName` feature for package references described above. For example:
348348

349349
```xml
350-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
350+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
351351
<PropertyGroup>
352352
<TargetFramework>netstandard2.1</TargetFramework>
353353
<SqlServerVersion>160</SqlServerVersion>
@@ -368,7 +368,7 @@ For other variants of SQL Server / Azure SQL Database there are dedicated packag
368368
Similar to package references you can also reference another project by using a `ProjectReference`. These references can be added manually to the project file or they can be added through Visual Studio. For example, consider the following example:
369369

370370
```xml
371-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
371+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
372372
<PropertyGroup>
373373
<TargetFramework>netstandard2.1</TargetFramework>
374374
</PropertyGroup>
@@ -382,7 +382,7 @@ Similar to package references you can also reference another project by using a
382382
This will ensure that `MyOtherProject` is built first and the resulting `.dacpac` will be referenced by this project. This means you can use the objects defined in the other project within the scope of this project. If the other project is representing an entirely different database, you can also use `DatabaseVariableLiteralValue` or SQLCMD variables on the `ProjectReference` similar to `PackageReference`:
383383

384384
```xml
385-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
385+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
386386
<PropertyGroup>
387387
<TargetFramework>netstandard2.1</TargetFramework>
388388
</PropertyGroup>
@@ -416,7 +416,7 @@ In order to solve circular references between databases that may have been incor
416416
`SuppressMissingDependenciesErrors` to both [Package References](#package-references) and [ProjectReferences](#project-references)):
417417

418418
```xml
419-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
419+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
420420
<PropertyGroup>
421421
<TargetFramework>netstandard2.1</TargetFramework>
422422
</PropertyGroup>
@@ -438,7 +438,7 @@ In order to solve circular references between databases that may have been incor
438438
You'll need to set the `PackageProjectUrl` property in the `.csproj` like this:
439439

440440
```xml
441-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
441+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
442442
<PropertyGroup>
443443
...
444444
<PackageProjectUrl>your-project-url</PackageProjectUrl>
@@ -513,7 +513,7 @@ To further customize the deployment process, you can use the following propertie
513513
In addition to these properties, you can also set any of the [documented](https://docs.microsoft.com/dotnet/api/microsoft.sqlserver.dac.dacdeployoptions) deployment options. These are typically set in the project file, for example:
514514

515515
```xml
516-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
516+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
517517
<PropertyGroup>
518518
...
519519
<BackupDatabaseBeforeChanges>True</BackupDatabaseBeforeChanges>
@@ -537,7 +537,7 @@ Most of those properties are simple values (like booleans, strings and integers)
537537
Instead of using `dotnet publish` to deploy changes to a database, you can also have a full SQL script generated that will create the database from scratch and then run that script against a SQL Server. This can be achieved by adding the following to the project file:
538538

539539
```xml
540-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
540+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
541541
<PropertyGroup>
542542
<GenerateCreateScript>True</GenerateCreateScript>
543543
<IncludeCompositeObjects>True</IncludeCompositeObjects>
@@ -565,7 +565,7 @@ Starting with version 2.7.0 of the SDK, there is support for running static code
565565
Static code analysis can be enabled by adding the `RunSqlCodeAnalysis` property to the project file:
566566

567567
```xml
568-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
568+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
569569
<PropertyGroup>
570570
<PropertyGroup>
571571
<TargetFramework>netstandard2.1</TargetFramework>
@@ -597,7 +597,7 @@ Any rule violations found during analysis are reported as build warnings.
597597
Individual rule violations or groups of rules can be configured to be reported as build errors as shown below.
598598

599599
```xml
600-
<Project Sdk="MSBuild.Sdk.SqlProj/3.0.0">
600+
<Project Sdk="MSBuild.Sdk.SqlProj/3.1.0">
601601
<PropertyGroup>
602602
<RunSqlCodeAnalysis>True</RunSqlCodeAnalysis>
603603
<CodeAnalysisRules>+!SqlServer.Rules.SRN0005;+!SqlServer.Rules.SRD*</CodeAnalysisRules>
@@ -692,6 +692,12 @@ While the SDK does not help you maintain a [refactor log](https://learn.microsof
692692
</ItemGroup>
693693
```
694694

695+
## SQL CLR objects support
696+
697+
It is not possible to include SQL CLR objects in `MSBuild.Sdk.SqlProj` projects, as they can only be built on .NET Framework.
698+
699+
You can work around this by "isolating" your SQL CLR objects in a separate `.sqlproj` project, build and pack the resulting `.dacpac` in a NuGet package on Windows, and then reference this package from your project. Read more about this approach in [this blog post](https://erikej.github.io/dacfx/sqlclr/2025/01/28/dacfx-sqlclr-msbuild-sdk-sqlproj.html).
700+
695701
## Known limitations
696702

697703
Since this is not an entire project system but only an MSBuild SDK we cannot provide IntelliSense for objects defined within the project. This limitation can be circumvented by connecting the SQL editor to a live database that is used for development purposes.

0 commit comments

Comments
 (0)