简体   繁体   English

在SSDT SQLPROJ中有条件地构建部署后

[英]Conditionally build Post-Deploy in SSDT SQLPROJ

I want to conditionally build the post-deploy script in my SSDT project, but i don't understand how to do that. 我想在我的SSDT项目中有条件地构建部署后脚本,但是我不知道该怎么做。 So normally the post-deploy script is built, but I want a way to NOT build or run the post-deploy script when doing a Debug build. 因此,通常会构建部署后脚本,但是我想要一种在调试构建时不构建或运行部署后脚本的方法。 I am running the build from the command-line, so i could pass in properties, but how could i use a property to not run the post-deploy script? 我从命令行运行构建,因此可以传递属性,但是如何使用属性不运行部署后脚本?

The options i see are SQLCMD, or editing the SQLPROJ file, or passing in properties, but I can't find any reference for what the available properties are and what not for SQLPROJ files. 我看到的选项是SQLCMD,或编辑SQLPROJ文件,或传递属性,但是我找不到关于可用属性是什么以及对于SQLPROJ文件不是什么的任何参考。

The file i want to conditionally build is located here: 我要有条件地生成的文件位于:

<ItemGroup>
    <PostDeploy Include="PostDeploymentScripts\Script.PostDeployment1.sql" />
</ItemGroup>  

My Debug build block looks like this: 我的Debug构建块如下所示:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <OutputPath>bin\Debug\</OutputPath>
    <BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <DefineDebug>true</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>  

And my command-line looks like this: 我的命令行如下所示:

msbuild $sqlprojFilePath /p:Configuration="Debug"

In your .sqlproj, add this line to occur after the import on Microsoft.Data.Tools.Schema.SqlTasks.targets 在您的.sqlproj中,添加此行以在Microsoft.Data.Tools.Schema.SqlTask​​s.targets上导入之后发生

Find this line in your project file after the import on *SqlTasks.targets. 在* SqlTask​​s.targets上导入后,在项目文件中找到此行。

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(MSBuildToolsVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />

<PropertyGroup Condition="'$(Configuration)'=='debug'">
  <DeployDependsOn />
  <SqlDeployDependsOn />
</PropertyGroup>

This removes the deployment projects from the dependency chain and can be modified to use an alternate property. 这会将部署项目从依赖关系链中删除,并且可以进行修改以使用替代属性。

<PropertyGroup Condition="'$(SkipDeployment)'=='true'">
  <DeployDependsOn />
  <SqlDeployDependsOn />
</PropertyGroup>

Command line: 命令行:

msbuild.exe mydb.sqlproj /p:SkipDeployment=true

Big Edit: 大修改:

Or you can take this: 或者,您可以这样做:

<ItemGroup>
    <PostDeploy Include="PostDeploymentScripts\Script.PostDeployment1.sql" />
</ItemGroup>  

and change it to read like so: 并将其更改为:

<ItemGroup Condition="'$(Configuration)'=='debug'">
    <PostDeploy Include="PostDeploymentScripts\Script.PostDeployment1.sql" />
</ItemGroup>  

You can do this with a SQLCMD variable. 您可以使用SQLCMD变量执行此操作。 Set one up in the project and check the value of that variable when publishing the project. 在项目中进行设置,并在发布项目时检查该变量的值。 I blogged about something like this here: 我在这里写过类似的博客:

http://schottsql.blogspot.com/2013/05/trick-to-not-run-prepost-sql-on-publish.html http://schottsql.blogspot.com/2013/05/trick-to-not-run-prepost-sql-on-publish.html

Not sure about the msbuild command-line as I've normally used sqlpackage.exe to push the changes. 由于我通常使用sqlpackage.exe来推送更改,因此不确定msbuild命令行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 注册表查询和在部署后脚本中使用输出? - Registry Query and Use Output in Post-Deploy Script? sqlproj生成后$(Configuration)在TFS上不正确 - sqlproj post-build $(Configuration) incorrect on TFS 在TeamCity 7构建服务器上构建* .sqlproj SSDT项目时,*。dacpac文件的文件命名错误 - Erratic file naming of *.dacpac files when building a *.sqlproj SSDT project on a TeamCity 7 build server Visual Studio SSDT 数据库项目 (.sqlproj) 构建 - 使用没有 MSBUILD (msbuild.exe) 的 CLI 生成.dacpac - Visual Studio SSDT Database project (.sqlproj) build - generate .dacpac using CLI without MSBUILD (msbuild.exe) msbuild忽略ValidateCasingOnIdentifiers用SSDT sqlproj生成sql - msbuild ignores ValidateCasingOnIdentifiers generating sql with SSDT sqlproj sqlproj的自定义构建操作 - Custom Build Action for sqlproj TFS 构建服务器上的无头构建 .sqlproj 文件 - Headless build .sqlproj file on TFS build server 从代码构建和发布sqlproj以进行集成测试 - Build and publish sqlproj from code for integration testing TeamCity / .sqlproj通过MSBuild构建 - 失败 - TeamCity/.sqlproj build via MSBuild — FAILED 如何根据构建配置有条件地部署app.config? - How to conditionally deploy an app.config based on build configuration?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM