Using Web Deploy (msdeploy) to publish a WebMatrix

2019-04-12 15:24发布

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.

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

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"

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.

It all works great.

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

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>"

This gives me

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. ...

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.

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.

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

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

[UPDATE - ANSWER]

One of the best things about StackOverflow, 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.

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

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...

1条回答
聊天终结者
2楼-- · 2019-04-12 16:00

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

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.

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

查看更多
登录 后发表回答