我有一個問題,它非常類似於我的舊問題Using variable in sql postdeployment build script? 但現在我不想做一個if/else並在發佈的腳本中包含sql代碼。我不想分享客戶之間的信息。發佈時如何不包含sql文件內容?
所以......這裏去
- 我在Visual Studio數據庫項目。
- 我也有2個客戶提供不同需求
我知道我可以
- 使用post.deployment腳本,包括我需要在Project.Properties設置varible SQL文件的內容。」 SQLCMD變量「。
,然後用它像這樣Script.PostDeployment.sql
:r ..\$(Customer)Setup.sql
在那裏我有2個文件
- Customer1Setup.sql
- Customer2Setup.sql
然後我將SQLCMD變量設置爲$(Customer)「Customer1」或「Customer2」,並且只包含我在SQLCMD中放置的那個變量。
但,當我想用變量的出版窗口默認一個覆蓋它
我知道我可以在構建腳本做到這一點somewho但我想要知道我是否可以使用當前工具並創建Customer1.publish.xml和Customer2.publish.xml文件,以便我知道如果發佈到Customer2,Customer1的某些內容不會與該腳本一起使用。
編輯1:
我創建了一個公共GitHub repository來試圖解決我的問題。希望有人可以看看並編輯它的工作。
編輯2:
這是我的測試項目的結果(與我的真實的),其中在3次測試我的每一個存在導致相同的。 Customer2/Customer3中的所有「材料」都包含在結果中。如果這是這樣運作的有一些開關或設置在I'm我的設置丟失(VS2015的數據庫項目)
SET NOEXEC ON
Print 'This print statement should not be in the publishing script if Customer variable is not customer1'
print 'Customer1 stuff from Customer1.sql'
SET NOEXEC OFF
IF('$(Customer)' <> 'customer2')
SET NOEXEC ON
Print 'This print statement should not be in the publishing script if Customer variable is not customer2'
print 'Customer2 stuff from Customer2.sql'
SET NOEXEC OFF
IF('$(Customer)' <> 'customer3')
SET NOEXEC ON
Print 'This print statement should not be in the publishing script if Customer variable is not customer3'
print 'Customer3 stuff from Customer3.sql'
SET NOEXEC OFF
編輯3
可能的複製http://stackoverflow.com/questions/7151021/conditional-logic-in-postdeployment-sql-script -using-sqlcmd) –
作爲腳本的一部分的條件邏輯有什麼問題? –
就像我在聊天中所說的:有時候,客戶端會在腳本中設置腳本,然後我不希望腳本中有任何其他客戶特定的東西。我只是想做出這個自動解決方案。但是我認爲這可能/應該只是在構建腳本中完成(Cake?)。但我發現奇怪的是,這並不是內置於工具中的。也許我應該寫一個VS數據庫擴展? – Sturla