使用Web部署(msdeploy)发布WebMatrix网站

问题描述:

我开始在WebMatrix中构建站点,然后切换到使用VS2010,这样我可以进行更好的Intellisense和调试.我一直在加载要部署的WebMatrix,并且运行良好.

I started building my site in WebMatrix and then switched to using VS2010 so I could have better Intellisense and debugging. I've been loading WebMatrix to deploy and it's been working fine.

但是,加载WebMatrix是PITA,我实际上希望在Web部署过程中具有更大的灵活性.

However, loading WebMatrix is a PITA and I actually want more flexibility over the web deployment process.

因此,我开始学习msdeploy.exe及其使用方法.我可以通过以下命令行成功使网站同步:

So I started learning about msdeploy.exe and how to use it. I was able to successfully get the site to sync as I wanted with the following command line:

msdeploy.exe
  -verb:sync 
  -dest:iisApp=MySite,wmsvc=www.mysite.com,username=administrator,password=blahblahblah
  -allowUntrusted 
  -skip:absolutePath=webdeploy.cmd 
  -skip:absolutePath=web.config 
  -skip:objectName=dirPath,absolutePath="App_Data" 
  -skip:objectName=dirPath,absolutePath="bin" 
  -skip:absolutePath=vwd.webinfo 
  -source:iisApp="C:\Users\charlie\Documents\Visual Studio 2010\WebSites\MySite"

我必须使用-allowTrusted,因为服务器上的证书使用的主机名不同于www.没关系我有一些-skips代表我不想写到目标的东西.

I had to use -allowTrusted because the cert on the server uses a differnt host name than www. No biggie. I have some -skips for stuff I don't want to write to the dest as well.

一切正常.

我在主机(AWS上的WebMatrix AMI)上使用SQL Server(Express).

I use SQL Server (Express) on my host (a WebMatrix AMI on AWS).

我也希望能够将数据库推送到主机.我正在尝试使用以下msdeploy命令:

I want to have the ability to push my database to the host as well. I am trying to use the following msdeploy commmand:

msdeploy.exe 
    -verb:sync 
    -source:dbFullSql="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=C:....\MySite.mdf;User instance=true" 
    -dest:dbFullSql="Server=www.mysite.com\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user;Pwd=<pwd>"

这给了我

Error: The database 'webmatrix_db' could not be created.
Error: A network-related or instance-specific error occurred while establishing aa
connection to SQL Server. The server was not found or was not accessible. ...

我认为我的问题是连接字符串.我从WebMatrix UI复制了Server=".\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user;Pwd=<pwd>,并在其前面加上了www.mysite.com,以为它需要我的主机名.

I think my problem is the connection string. I copied Server=".\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user;Pwd=<pwd> from the WebMatrix UI and pre-pended it with www.mysite.com thinking it needed my hostname somewhere.

很显然,这是不正确的,我也找不到任何有效的连接字符串示例.

Obviously this is not correct and I can't find any examples of connection strings that work either.

请注意,此服务器未直接公开SQL.我假设WebMatrix对msdeploy的调用首先使用我的管理员凭据(而不是SQL凭据)进行连接,然后msdeploy调用远程主机上的SQL命令.在上面给出的第一个示例的-dest选项中,我需要类似...wmsvc=www.mysite.com,username=administrator,password=blahblahblah的东西.

Note that SQL is not exposed directly by this server. I assume WebMatrix's invocation of msdeploy is connecting using my admin credentials (not the SQL credentials) first and then msdeploy invokes the SQL commands on the remote host. I need something like the ...wmsvc=www.mysite.com,username=administrator,password=blahblahblah in the -dest option of the first example I gave above.

如果我能看到WebMatrix如何调用msdeploy的日志,那将是非常棒的.

It would be awesome if I could see a log of how WebMatrix was invoking msdeploy.

做我想做的正确的msdeploy命令是什么?

What is the correct msdeploy command to do what I want?

[更新-答复]

关于*的最好的事情之一是,发布问题确实会让您思考自己在做什么.发布上述内容后不久,我意识到-dest参数中的wmsvc=www.mysite.com,username=administrator,password=blahblahblah参数是关键.问题变成了如何正确地将其添加到我的特定示例中.

One of the best things about *, is that posting a question really makes you think about what you are doing. Shortly after I posted the above, I realized the wmsvc=www.mysite.com,username=administrator,password=blahblahblah parameter in the -dest parameter was the key. The question became how to correctly add it to my specific example.

此msdeploy命令行现在可以正确连接:

This msdeploy command line now connects correctly:

msdeploy.exe -verb:sync -source:dbFullSql="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=C:\Users\charlie\Documents\Visual Studio 2010\WebSites\Fiinom\App_Data\MySite.mdf;User instance=true" -dest:dbFullSql="Server=.\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user; Pwd=rI2vP3rK6hV8nN8",wmsvc=www.mysite.com,username=administrator,password=blahblahblah -allowUntrusted

现在,msdeploy已成功连接并执行命令,我需要弄清楚如何使其实际合并数据库.现在,这给了我一个错误,那就是表已经存在并且无法创建...

Now that msdeploy is connecting successfully and executing commands, I need to figure out how to make it actually merge the database. Right now it's giving me an error that a table already exists and can't create it...

这与您关于合并数据库的旁注有关.

This is related to your side comment on merging the database...

当前,Web Deploy没有任何支持数据库合并的提供程序-dbFullSql提供程序使用SQL Server管理对象("SMO")编写数据库内容的脚本,然后将其应用到另一端.因此,有效地,Web Deploy将仅用源数据库覆盖目标数据库.

Currently Web Deploy does not have any provider that supports database merges - the dbFullSql provider uses SQL Server Management Objects ("SMO") to script out the db contents and we then apply it on the other side. Effectively Web Deploy thus will only overwrite the destination db with the source db.

如果可以合并",则可以使用SMO脚本选项解决该表已存在的错误-这是WebMatrix进行的以使db发布/下载工作.在您的来源中只需添加: ,scriptDropsFirst = true (此脚本为源数据库中的所有对象删除了脚本,因此,如果它们存在于目标数据库中,它们将被删除并且不会阻止您) 您可能还需要: ,copyAllUsers = false (如果您不是远程SQL数据库的系统管理员,则可能无法创建登录名,这是服务器级的操作.通常,如果不使用此设置,则会收到错误消息关于创建登录名或登录名不存在的信息,因为SMO将您的数据库用户脚本化为"for LOGIN",并且该登录名在服务器上不存在

If you are okay with that as a "merge" you can get around that table already exists error by using SMO scripting options - this is what WebMatrix does to make the db publishing/downloading work. To your source just add: ,scriptDropsFirst=true (this scripts out drops for all the objects in your source database so that if they exist on the destination they will get dropped and won't block you) You might also need: ,copyAllUsers=false (if you aren't a sysadmin on the remote SQL database, chances are you won't be able to create logins, which are a server-level action. Typically if you don't use this setting, you'll get an error about creating a login, or login doesn't exist, because SMO scripts our your database user as "for LOGIN " and that login doesn't exist on the server)

希望有帮助! 克里斯蒂娜

Hope that helps! Kristina