Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 2bb4066

Browse files
Merge pull request #33360 from dzsquared/sqlprojects/feb2025
expanding sqlcmd var for package reference
2 parents 10173eb + c41206f commit 2bb4066

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

docs/tools/sql-database-projects/concepts/package-references.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Reference database objects with package references."
44
author: dzsquared
55
ms.author: drskwier
66
ms.reviewer: maghan, randolphwest
7-
ms.date: 08/30/2024
7+
ms.date: 03/02/2025
88
ms.service: sql
99
ms.subservice: sql-database-projects
1010
ms.topic: concept-article
@@ -42,6 +42,33 @@ The following example includes a package reference to the `Contoso.AdventureWork
4242
</Project>
4343
```
4444

45+
The following example includes a package reference to the `Contoso.AdventureWorks` package as a database reference for a different database (AdventureWorks) on the same server where the objects in the package become part of the database model in the SQL project:
46+
47+
```xml
48+
...
49+
<ItemGroup>
50+
<PackageReference Include="Contoso.AdventureWorks" Version="1.1.0">
51+
<DatabaseSqlCmdVariable>AdventureDB</DatabaseSqlCmdVariable>
52+
<DacpacName>AdventureWorks</DacpacName>
53+
</PackageReference>
54+
</ItemGroup>
55+
<ItemGroup>
56+
<SqlCmdVariable Include="AdventureDB">
57+
<DefaultValue>AdventureWorks</DefaultValue>
58+
<Value>$(SqlCmdVar__1)</Value>
59+
</SqlCmdVariable>
60+
</ItemGroup>
61+
</Project>
62+
```
63+
64+
In this example, the AdventureWorks `.dacpac` file is published as a package `Contoso.AdventureWorks` version `1.1.0` to a NuGet feed. The `<DatabaseSqlCmdVariable>` element specifies the name of the database on the same server where the objects in the package are located and would be used to indicate this reference in three-part naming. The [SQLCMD variable](sqlcmd-variables.md) `AdventureDB` is used to set the database name at deployment time and is used in the project similarly to this example query:
65+
66+
```sql
67+
SELECT * FROM [$(AdventureDB)].dbo.Customers
68+
```
69+
70+
The `<DacpacName>` element specifies the name of the `.dacpac` file for the package reference, without the file extension or path. The `<DacpacName>` element is optional and is only required when the name of the `.dacpac` file is different from the name of the package.
71+
4572
### System databases
4673

4774
The SQL system databases (`master`, `msdb`) are published on NuGet.org as database reference packages. These packages contain the schema for the system databases and can be used as package references in SQL projects. The system database packages are versioned to align with the version of SQL Server they're associated with. For example, the `master` system database package for SQL Server 2022 is `Microsoft.SqlServer.Dacpacs.Master` version `160.2.1` and can be added to a SQL project as a package reference:
@@ -82,7 +109,9 @@ Package metadata can be specified by properties inside the `<PropertyGroup>` ele
82109
<Company>Contoso Outdoors</Company>
83110
```
84111

85-
The `.nupkg` file created by the `dotnet pack` command can be published to a NuGet feed for use in SQL projects. This database objects can be viewed by anyone with access to the package, so consideration should be made for selecting a public or private feed location. For more information, see [Hosting with private package feeds](/nuget/hosting-packages/overview).
112+
The `.nupkg` file created by the `dotnet pack` command can be published to a NuGet feed for use in SQL projects. These database objects can be viewed by anyone with access to the package, so consideration should be made for selecting a public or private feed location. For more information, see [Hosting with private package feeds](/nuget/hosting-packages/overview).
113+
114+
When referencing a package where the `PackageId` is different from the name of the `.dacpac` file, the `<DacpacName>` element is required in the package reference when consuming the package.
86115

87116
## Related content
88117

0 commit comments

Comments
 (0)