如何通过MsBuild命令行部署CLR存储过程?

时间:2011-10-03 12:10:37

标签: msbuild sqlclr clrstoredprocedure

我可以通过右键单击选择部署来从解决方案资源管理器部署SqlClr项目项目。但是,我想要一个命令行版本,我也可以在其中指定自定义ConnectionString。

1 个答案:

答案 0 :(得分:1)

命令为msbuild MySqlClrProject.csproj /T:deploy。这假定代码是构建的,并且至少在我的机器上,默认情况下构建调试版本。如果要重建解决方案,部署发布二进制文件并使用自定义连接字符串,则命令为msbuild MySqlClrProject.csproj /T:Clean;Build;Deploy /p:Configuration=Release;ConnectionString="Data Source= .;Initial Catalog=dropme;Integrated Security=True"

您需要从x86 2010命令提示符(MSBuild 4.0)执行此操作。它在Visual Studio 2008(MSBuild 3.5)中不起作用。我没有Visual Studio 2012来查看它是否在那里工作。

如果您尝试从64位命令提示符运行此命令,您将获得以下内容:

c:\Users\jdearing\Documents\MySqlClrProject\MySqlClrProject.csproj(48,11): error MSB4019: The imported project "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SqlServer.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.     

以下是成功运行命令的示例:

Setting environment for using Microsoft Visual Studio 2008 x86 tools.

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC>cd c:\Users\jdearing\Documents\MySqlClrProject

c:\Users\jdearing\Documents\MySqlClrProject>msbuild MySqlClrProject.csproj /T:deploy
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.261]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 7/11/2012 4:58:04 PM.
Project "c:\Users\jdearing\Documents\MySqlClrProject\MySqlClrProject.csproj" on node 1 (Deploy target(s)).
SqlClrDeploy:
  Beginning deployment of assembly MySqlClrProject.dll to server . : dropme
  The following error might appear if you deploy a SQL CLR project that was built for a version of the .NET Framework that is incompatible with the target instance of SQL Server: "Deploy error SQL01268: CREATE ASSEMBLY for assembly failed because assembly failed verification". To resolve this issue, open the properties for the project, and change the .NET Framework version.
  Deployment script generated to:
  c:\Users\jdearing\Documents\MySqlClrProject\bin\Debug\MySqlClrProject.sql

  Dropping [MySqlClrProject].[SqlAssemblyProjectRoot]...
  Creating [MySqlClrProject].[SqlAssemblyProjectRoot]...
  The transacted portion of the database update succeeded.
  Deployment completed
AfterDeploy:
  ---SqlReference---
  Data Source=.;Initial Catalog=dropme;Integrated Security=True
Done Building Project "c:\Users\jdearing\Documents\MySqlClrProject\MySqlClrProject.csproj" (Deploy target(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:09.37

c:\Users\jdearing\Documents\MySqlClrProject>