2011-10-03 128 views
4

我可以從解決方案資源管理器中通過右鍵單擊選擇部署來部署SqlClr項目項目。不過,我想要一個命令行版本,我也可以指定自定義ConnectionString。如何通過MsBuild命令行部署CLR存儲過程?

+0

啓動VS命令提示符。然後運行'devenv/deploy/out log.log yoursolution.sln'。在log.log中查找如何部署的線索,對不起,我不能做得比這更好:/ –

+3

Taheren,如果你接受他們的答案,人們會更傾向於回答你的問題。 –

回答

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>