From 2baa8f881609143933d5a1601e1aaf8bb72ad18d Mon Sep 17 00:00:00 2001 From: Erik Ejlskov Jensen Date: Mon, 15 Jul 2024 14:35:35 +0200 Subject: [PATCH] Build a Nupkg without a .nuspec (#579) * Enable dotnet pack without a .nuspec file fixes #283 * Update readme * Set package type * avoid breaking change * Update TestProject * Remove property * Move Pack item to Props * Remove PackageType to fix VS NuGet restore issue * Update readme * Simpler * Remove package type to avoid confusion see https://github.com/NuGet/Home/issues/10468 --- README.md | 71 +++++++++---------------- src/MSBuild.Sdk.SqlProj/Sdk/Sdk.props | 3 +- src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets | 1 - test/TestProject/TestProject.nuspec | 20 ------- 4 files changed, 26 insertions(+), 69 deletions(-) delete mode 100644 test/TestProject/TestProject.nuspec diff --git a/README.md b/README.md index 936ac68f..0e0037c1 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ dotnet new sqlproj -s Sql130 You should now have a project file with the following contents: ```xml - + netstandard2.0 Sql130 @@ -94,7 +94,7 @@ If you already have a SSDT (.sqlproj) project in your solution, you can keep tha 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`: ```xml - + netstandard2.0 Simple @@ -112,7 +112,7 @@ Like `.sqlproj` projects `MSBuild.Sdk.SqlProj` supports controlling T-SQL build Treating warnings as errors can be optionally enabled by adding a property `TreatTSqlWarningsAsErrors` to the project file: ```xml - + True ... @@ -124,7 +124,7 @@ Treating warnings as errors can be optionally enabled by adding a property `Trea To suppress specific warnings from being treated as errors, add a comma-separated list of warning codes to `SuppressTSqlWarnings` property in the project file: ```xml - + 71558,71502 True @@ -136,7 +136,7 @@ To suppress specific warnings from being treated as errors, add a comma-separate You can suppress warnings for a specific file by adding `SuppressTSqlWarnings` for this file: ```xml - + ... @@ -156,7 +156,7 @@ Support for pre- and post deployment scripts has been added in version 1.1.0. Th To include these scripts into your `.dacpac` add the following to your `.csproj`: ```xml - + ... @@ -173,7 +173,7 @@ It is important to note that scripts in the `Pre-Deployment` and `Post-Deploymen 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: ```xml - + True ... @@ -189,7 +189,7 @@ By default the pre- and/or post-deployment script of referenced packages (both [ 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: ```xml - + ... @@ -213,7 +213,7 @@ Especially when using pre- and post deployment scripts, but also in other scenar `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. ```xml - + netstandard2.0 @@ -227,7 +227,7 @@ Especially when using pre- and post deployment scripts, but also in other scenar 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: ```xml - + netstandard2.0 Sql160 @@ -244,7 +244,7 @@ This will add a reference to the `tools\SomeOtherDacpac.dacpac` file inside the 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: ```xml - + netstandard2.0 @@ -261,7 +261,7 @@ You can also use SQLCMD variables to set references, similar to the behavior of >Note: Don't forget to define appropriate [SQLCMD variables](#sqlcmd-variables) ```xml - + netstandard2.0 @@ -302,7 +302,7 @@ sqlpackage 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: ```xml - + netstandard2.0 160 @@ -322,7 +322,7 @@ For other variants of SQL Server / Azure SQL Database there are dedicated packag 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: ```xml - + netstandard2.0 @@ -336,7 +336,7 @@ Similar to package references you can also reference another project by using a 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`: ```xml - + netstandard2.0 @@ -370,7 +370,7 @@ In order to solve circular references between databases that may have been incor `SuppressMissingDependenciesErrors` to both [Package References](#package-references) and [ProjectReferences](#project-references)): ```xml - + netstandard2.0 @@ -386,41 +386,18 @@ In order to solve circular references between databases that may have been incor ``` ## Packaging support -`MSBuild.Sdk.SqlProj` supports packaging your project into a [NuGet](https://www.nuget.org) package using the `dotnet pack` command. In order for this to work, you'll need to add a `.nuspec` file next to your project file with the same name. For example, if your `.csproj` is called `TestProject.csproj` you'll need to add a `TestProject.nuspec` file in the same folder. Fill this file with the following contents and replace the placeholder with the appropriate value: -```xml - - - - $id$ - $version$ - $description$ - $authors$ - $authors$ - $copyright$ - $projecturl$ - $tags$ - - - - - - - - - -``` - -> Note: The above `.nuspec` file will result in a package that includes the .dacpac of the project as well as any referenced .dacpac file's (those from `PackageReference`). This is by design since you'll probably need those later on when deploying the .dacpac. If you want to only include the .dacpac of the project replace `*.dacpac` with `$id$.dacpac`. +`MSBuild.Sdk.SqlProj` version 2.8.0 and later supports packaging your project into a [NuGet](https://www.nuget.org) package using the `dotnet pack` command. -Additionally you'll need to set the `PackageProjectUrl` property inside of the `.csproj` like this: +You'll need to set the `PackageProjectUrl` property in the `.csproj` like this: ```xml - + ... your-project-url + ``` @@ -490,7 +467,7 @@ To further customize the deployment process, you can use the following propertie 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: ```xml - + ... True @@ -513,7 +490,7 @@ Most of those properties are simple values (like booleans, strings and integers) 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: ```xml - + True True @@ -539,7 +516,7 @@ Starting with version 2.7.0 of the SDK, there is support for running static code Static code analysis can be enabled by adding the `RunSqlCodeAnalysis` property to the project file: ```xml - + True -SqlServer.Rules.SRD0006;-Smells.* @@ -556,7 +533,7 @@ Any rule violations found during analysis are reported as build warnings. Individual rule violations or groups of rules can be configured to be reported as build errors as shown below. ```xml - + True +!SqlServer.Rules.SRN0005;+!SqlServer.Rules.SRD* diff --git a/src/MSBuild.Sdk.SqlProj/Sdk/Sdk.props b/src/MSBuild.Sdk.SqlProj/Sdk/Sdk.props index 6aa68e8a..8426e615 100644 --- a/src/MSBuild.Sdk.SqlProj/Sdk/Sdk.props +++ b/src/MSBuild.Sdk.SqlProj/Sdk/Sdk.props @@ -26,7 +26,7 @@ false false True - $(MSBuildProjectName).nuspec + $(MSBuildProjectName).nuspec @@ -45,6 +45,7 @@ + diff --git a/src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets b/src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets index 8b9263b0..4598709d 100644 --- a/src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets +++ b/src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets @@ -64,7 +64,6 @@ tags=$(PackageTags); configuration=$(Configuration); tfm=$(TargetFramework); - packagetype=Dacpac diff --git a/test/TestProject/TestProject.nuspec b/test/TestProject/TestProject.nuspec deleted file mode 100644 index cd8b9dd9..00000000 --- a/test/TestProject/TestProject.nuspec +++ /dev/null @@ -1,20 +0,0 @@ - - - - $id$ - $version$ - $description$ - $authors$ - $authors$ - $copyright$ - $projecturl$ - $tags$ - - - - - - - - - \ No newline at end of file