How to specify a destination folder with MSDeploy - msdeploy

I have MSDeploy successfully deploying a web package zip file to a remote IIS website using a command like this
MyDeployCommand.deploy.cmd /T /M:https://MyServer:8172/msdeploy.axd -allowUntrusted /U:Username /P:Password /A:Basic "-setParam:name='IIS Web Application Name',value='My Website Name'"
Although this works, it defaults to the current directory that the website is pointing to. I'd like to change the physical path. I've tried a number of parameters with no success and was wondering if this is even possible to do.
Thanks to chief7 for pointing out the appcmd, which on the target works eg
%windir%\system32\inetsrv\appcmd set site /site.name:"My Website Name" /application[path='/'].virtualDirectory[path='/'].physicalPath:"C:\new\path"
However if I try the same thing on the remote machine eg
"%MSDeployPath%msdeploy.exe" -verb:sync -source:runCommand="%windir%\system32\inetsrv\appcmd.exe set site /site.name:;quot;My Website Name;quot; /application[path='/'].virtualDirectory[path='/'].physicalPath:;quot;C:\new\path;quot;",dontUseCommandExe=true -dest:auto
Its coming back with
Error: The system cannot find the file specified. (Exception from HRESULT: 0x80070002) which I assume is referring to the appcmd. I added
dontUseCommandExe=true
to get around the problem of it being called via cmd.exe

You can extend the WebDeploy manifest to alter the site/app path with a RunCommand provider.
<runcommand path="%windir%\system32\inetsrv\appcmd set app /app.name:&quot;Default Web Site/app12&quot; /[path='/'].physicalPath:C:\temp\app12" waitInterval="5000"/>
http://www.dotnetcatch.com/2016/06/28/webdeploymsdeploy-quick-tip-change-iis-siteapp-physical-path-with-msdeploy/
http://www.dotnetcatch.com/2016/05/19/extending-the-webdeploy-manifest/
The appHostConfig provider is also supposed to let you change the directory but this was easier.

Related

.NET Core - same project running under iis express on different drive

I recently bought a new computer. I moved the drives from my old computer to the new one, installed everything I needed to and opened my project. Now I'm trying to run my project in IIS express but it displaying an error specifying an html output as log file.
When I look at the html problem, it's a 500 error message generated by what looks likes an IIS page. It's saying that the config file cannot be found:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid
Config File
\\?\F:\Development\MyProject\API\web.config
When I switched to the new machine drive letters were changed, so the code I'm running is no longet on drive F like in the message above - it's now on a different drive. I've looked in my code - I have no reference anywhere to a specific path.
I've tried to do clean and rebuild but it doesn't work.
If I look inside files for the path I see that the DLLs are compiled with PDB file path inside them. Why is that? And what happens later on on production?
Also, how do I fix this problem? why does it keeps looking for old location?
I'm fairly sure the IIS Express metabase still has the old path configured for this site. Please see the following answer for how to locate the metabase file (it's usually here: \Documents\IISExpress\config\applicationhost.config):
Where is the IIS Express configuration / metabase file found?
I'm not sure what the most correct way is to correct the problem, but you should be able to manually edit this file and update the "physicalPath" attribute for your site to the correct path to resolve this problem.
I don't know the exact cause of my problem, but the solution was to delete all bin directories from all project folders and re-compile.
To delete the bin directory from all my project I wrote the following PowerShell script:
Get-ChildItem -Path . -Filter *bin* –Recurse | Remove-Item -Recurse -Confirm

How to handle path on azure for XmlDocumentationProvider

I am using azure for deployment of my new Web API's, I am new with deployment on IIS and azure.
I have added my Web API's on azure as web application, and it's working fine, till I added documentation for each API's functions. After adding description I uncomment line below from HelpPageConfig.cs.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
It's working finr locally, and I am able to see all descriptions, but when I published it on azure, I am getting error saying,
Could not find a part of the path 'D:\home\site\wwwroot\App_Data\XmlDocument.xml'.
site url : http://mejodo.azurewebsites.net/
Do I need to change path ?
File is already created in my system on D:\home\site\wwwroot\App_Data directory.
What changes I need to do to make it work ?
I had the same issue. For me the file was generated. Please follow the below steps.
Click on show all files in solution explorer.
Check whether you have a file in App_Data folder
If you have the file, right click and include the same in your project.
Now build and publish to Azure.
I hope this will work. Thanks
In my case XmlDocument.xml had to be added in Visual Studio to the App_Data folder within the solution using 'add existing item'.
Just add to your project new folder "App_Data" with XmlDocument.xml and publish
When you say that you have Web API's on azure as web application, do you mean that they are applications under the site ? If yes, then I think you are missing the application name in the path to the XML file.
Try going to mejodo.scm.azurewebsites.net > debug console > powershell to see the exact folder structure....
You must verify that the line in the HelpPageConfig.cs file in the Area>HelpPage>App_Start folder.
that is in the register method, this line is
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
this uncommented
then you must verify that in the project configuration, in the build XML documentation file, this is the same path as the above mentioned line.
When you publish the xml file goes in the bin folder, so change 'D:\home\site\wwwroot\App_Data\XmlDocument.xml'.
to
'D:\home\site\wwwroot\bin\XmlDocument.xml'.
and it should work.

Copying files to a specific IIS directory using startup cmd in Azure

I want to create a startup cmd task in an Azure web role to copy a specific file into the inetpub\custerr\en-US directory before the role starts. Ideally, I'd like to be able to override the default error response html files. The overriding file will be stored inside the VS solution for the web role.
The following is a screenshot from IIS Manager's Error Pages window.
I'm not exactly sure how to do this. I suppose %SystemDrive%\inetpub\custerr\en-US should be the path to destination. How do I get the absolute/relative path to the file to be copied? I was thinking of adding it under the web role project and setting its Copy to Output Directory to Copy Always. What will the code in the startup cmd look like?
There is an alternative way of doing the same, thought it might help you.
Check this: Enable custom errors in Azure

Is it possible to modify web.config of existing site using MSDeploy?

Is it possible to modify (or just replace) web.config of existing site using MSDeploy?
It's possible to replace certain sections (specified with an xPath query or regular expression) of the web config file. Use the -declareParam en -setParam commandline switches for that.
Like so
msdeploy -verb:sync -source:apphostconfig="Default Web Site" -dest:package=ParameterPackage.zip -declareParam:name=param,kind=XmlFile,scope=web.config,match=//add/#value
or so:
msdeploy -verb:sync -source:package=ParameterPackage.zip -dest:auto -setParam:name=param,value=MyDefaultWebPage.htm
You can find more info here if you're using the command line.
If your working with importing and exporting packages in and from IIS you can create a parameters.xml file. Vishal Joshi has lots of good posts about how to use msdeploy (for example this)
Yes you can do this. I just posted a blog on this at http://sedodream.com/2012/02/14/HowToUpdateASingleFileUsingWebDeployMSDeploy.aspx but I'm also copying the content below for you.
The other day I saw a question posted on StackOverflow asking if it was possible to update web.config using MSDeploy. I actually used a technique where I updated a single file in one of my previous posts at How to take your web app offline during publishing but it wasn’t called out too much. In any case I’ll show you how you can update a single file (in this case web.config) using MSDeploy.
You can use the contentPath provider to facilitate updating a single file. Using contentPath you can sync either a single file or an entire folder. You can also use IIS app paths to resolve where the file/folder resides. For example if I have a web.config file in a local folder named “C:\Data\Personal\My Repo\sayed-samples\UpdateWebConfig” and I want to update my IIS site UpdateWebCfg running in the Default Web Site on my folder I would use the command shown below.
%msdeploy% -verb:sync -source:contentPath="C:\Data\Personal\My Repo\sayed-samples\UpdateWebConfig\web.config" -dest:contentPath="Default Web Site/UpdateWebCfg/web.config"
From the command above you can see that I set the source content path to the local file and the dest content path using the IIS path {SiteName}/{AppName}/{file-path}. In this case I am updating a site running in IIS on my local machine. In order to update one that is running on a remote machine you will have to add ComputerName and possibly some other values to the –dest argument.
You can view the latest sources for this sample at my github repo.

ASP.NET: debugging in same directory than publishing

I want to debug my asp.net application in same directory than I publish, so absolute paths are the same as real environment.
I try to activate use local IIS in "Web" properties but I get an error saying: I need to create virtual directory (actually it already exists in that directory) and if I try to creat it I get a cryptic error saying there is already a different folder assigned (or something similar)
Thank you
You mean to debug from the local IIS or any remote server directly right?
Close the VS. Open the .sln file in notepad, there will be a line on top like
Project("{random numbers}") = "test", "..\..\WebSites\test\", "{random numbers}"
Change the second parameter (relative path of your project folder in file system) to the address of your virtual directory. Like:
Project("{random numbers}") = "test", ""http://localhost/test/"", "{random numbers}"
Also if you are using IIS7, change the virtual directory to application.

Resources