You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add test project
* Allow overriding the dacpac name
* Add some docs about the new feature
* Remove unnecessary parameter
* Add scenario for same DacpacName as package
* Added a dedicated section about system databases
* Fix typo
* Fixed another typo
Copy file name to clipboardexpand all lines: README.md
+56-19
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ dotnet new sqlproj -s Sql130
42
42
You should now have a project file with the following contents:
43
43
44
44
```xml
45
-
<ProjectSdk="MSBuild.Sdk.SqlProj/2.2.0">
45
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
46
46
<PropertyGroup>
47
47
<TargetFramework>netstandard2.0</TargetFramework>
48
48
<SqlServerVersion>Sql130</SqlServerVersion>
@@ -92,7 +92,7 @@ If you already have a SSDT (.sqlproj) project in your solution, you can keep tha
92
92
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`:
@@ -122,7 +122,7 @@ Treating warnings as errors can be optionally enabled by adding a property `Trea
122
122
To suppress specific warnings from being treated as errors, add a comma-separated list of warning codes to `SuppressTSqlWarnings` property in the project file:
@@ -134,7 +134,7 @@ To suppress specific warnings from being treated as errors, add a comma-separate
134
134
You can suppress warnings for a specific file by adding `SuppressTSqlWarnings` for this file:
135
135
136
136
```xml
137
-
<ProjectSdk="MSBuild.Sdk.SqlProj/2.2.0">
137
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
138
138
<PropertyGroup>
139
139
...
140
140
</PropertyGroup>
@@ -154,7 +154,7 @@ Support for pre- and post deployment scripts has been added in version 1.1.0. Th
154
154
To include these scripts into your `.dacpac` add the following to your `.csproj`:
155
155
156
156
```xml
157
-
<ProjectSdk="MSBuild.Sdk.SqlProj/2.2.0">
157
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
158
158
<PropertyGroup>
159
159
...
160
160
</PropertyGroup>
@@ -171,7 +171,7 @@ It is important to note that scripts in the `Pre-Deployment` and `Post-Deploymen
171
171
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`. As of version 1.11.0 this can be optionally enabled by adding a property `RunScriptsFromReferences` to the project file as in the below example:
@@ -187,7 +187,7 @@ By default the pre- and/or post-deployment script of referenced packages (both [
187
187
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 through the use of SQLCMD variables, added in version 1.1.0. These variables can be defined in your project file using the following syntax:
188
188
189
189
```xml
190
-
<ProjectSdk="MSBuild.Sdk.SqlProj/2.2.0">
190
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
191
191
<PropertyGroup>
192
192
...
193
193
</PropertyGroup>
@@ -205,13 +205,13 @@ Especially when using pre- and post deployment scripts, but also in other scenar
205
205
</Project>
206
206
```
207
207
208
-
> Note: In versions prior to 1.11.0 the `DefaultValue` element displayed above was not used. As of version 1.11.0 the value of `Value` is checked first and if it found to be empty we'll fall back to `DefaultValue`.
208
+
> Note: In versions prior to 1.11.0 the `DefaultValue` element displayed above was not used. As of version 1.11.0 the value of `Value` is checked first and if it found to be empty we'll fall back to `DefaultValue`.
209
209
210
210
## Package references
211
211
`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.
212
212
213
213
```xml
214
-
<ProjectSdk="MSBuild.Sdk.SqlProj/2.2.0">
214
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
215
215
<PropertyGroup>
216
216
<TargetFramework>netstandard2.0</TargetFramework>
217
217
</PropertyGroup>
@@ -222,10 +222,27 @@ Especially when using pre- and post deployment scripts, but also in other scenar
222
222
</Project>
223
223
```
224
224
225
-
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. 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:
225
+
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:
This will add a reference to the `tools\SomeOtherDatabase.dacpac` file inside the `MyDatabasePackage` package. Note that if that file doesn't exist within the package, the package reference will still be silently ignored. However the build will most likely fail if your project actually references objects from the reference package.
241
+
242
+
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:
243
+
244
+
```xml
245
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
229
246
<PropertyGroup>
230
247
<TargetFramework>netstandard2.0</TargetFramework>
231
248
</PropertyGroup>
@@ -242,7 +259,7 @@ You can also use SQLCMD variables to set references, similar to the behavior of
242
259
>Note: Don't forget to define appropriate [SQLCMD variables](#sqlcmd-variables)
243
260
244
261
```xml
245
-
<ProjectSdk="MSBuild.Sdk.SqlProj/2.2.0">
262
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
246
263
<PropertyGroup>
247
264
<TargetFramework>netstandard2.0</TargetFramework>
248
265
</PropertyGroup>
@@ -264,7 +281,7 @@ You can also use SQLCMD variables to set references, similar to the behavior of
264
281
</Project>
265
282
```
266
283
In this scenario you can access the objects defined by `MyDatabasePackage` by using the `[$(SomeOtherServer)].[$(SomeOtherDatabase)].[<schema>].[<object>]` syntax.
267
-
Also you can combine `ServerSqlCmdVariable` with `DatabaseVariableLiteralValue` and use `[$(SomeOtherServer)].[SomeOtherDatabase].[<schema>].[<object>]` syntax
284
+
Also you can combine `ServerSqlCmdVariable` with `DatabaseVariableLiteralValue` and use `[$(SomeOtherServer)].[SomeOtherDatabase].[<schema>].[<object>]` syntax.
268
285
269
286
When deploying a dacpac with references to other dacpacs, if you want the contents of all dacpacs to be deployed to a single database you will need to specify the `IncludeCompositeObjects` property. For example:
270
287
@@ -279,11 +296,31 @@ sqlpackage
279
296
/Properties:IncludeCompositeObjects=True
280
297
```
281
298
299
+
## Referencing system databases
300
+
Microsoft has recently 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:
The above example references the `master` database from the [Microsoft.SqlServer.Dacpacs](https://www.nuget.org/packages/Microsoft.SqlServer.Dacpacs) NuGet package. Please note that there are different versions of that package for different versions of SQL Server. It is recommended to reference the same version of the package as the `SqlServerVersion` you are targeting with your project, as seen in the example above.
316
+
317
+
For the Azure SQL and Synapse variants of SQL Server there are dedicated packages: [Microsoft.SqlServer.Dacpacs.Azure](https://www.nuget.org/packages/Microsoft.SqlServer.Dacpacs.Azure) and [Microsoft.SqlServer.Dacpacs.Synapse](https://www.nuget.org/packages/Microsoft.SqlServer.Dacpacs.Synapse) respectively.
318
+
282
319
## Project references
283
320
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:
284
321
285
322
```xml
286
-
<ProjectSdk="MSBuild.Sdk.SqlProj/2.2.0">
323
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
287
324
<PropertyGroup>
288
325
<TargetFramework>netstandard2.0</TargetFramework>
289
326
</PropertyGroup>
@@ -297,7 +334,7 @@ Similar to package references you can also reference another project by using a
297
334
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`:
298
335
299
336
```xml
300
-
<ProjectSdk="MSBuild.Sdk.SqlProj/2.2.0">
337
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
301
338
<PropertyGroup>
302
339
<TargetFramework>netstandard2.0</TargetFramework>
303
340
</PropertyGroup>
@@ -331,7 +368,7 @@ In order to solve circular references between databases that may have been incor
331
368
`SuppressMissingDependenciesErrors` to both [Package References](#package-references) and [ProjectReferences](#project-references)):
332
369
333
370
```xml
334
-
<ProjectSdk="MSBuild.Sdk.SqlProj/2.2.0">
371
+
<ProjectSdk="MSBuild.Sdk.SqlProj/2.5.0">
335
372
<PropertyGroup>
336
373
<TargetFramework>netstandard2.0</TargetFramework>
337
374
</PropertyGroup>
@@ -451,7 +488,7 @@ To further customize the deployment process, you can use the following propertie
451
488
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:
@@ -474,7 +511,7 @@ Most of those properties are simple values (like booleans, strings and integers)
474
511
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:
0 commit comments