Azure: Include unreferenced DLLs when publish - visual-studio

I was struggling to publish my project because some DLLs were missing. After some investigations, I found what I was looking for:
http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx
Here my code:
<Target Name="CustomCollectFiles">
<Message Text="Publishing unreferenced DLLs" Importance="High" />
<ItemGroup>
<_CustomFiles Include="$(UnreferencedDlls)" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
It is working fine now but only when I publish on local. When I try to publish on Azure, these same DLLs are missing. So I tried to add the following line:
<DestinationRelativePath>obj\Release\Package\PackageTmp\bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
Because when I publish on azure, the Output says:
Copying all files to temporary location below for package/publish:
obj\Release\Package\PackageTmp.
But still, the DLLs are missing and I have no idea how to add them when I'm publishing on Azure.

I find a solution. The first one add the DLLs when I deploy on my local machine and the second do the same thing but when I deploy the app on Azure.
<PropertyGroup>
<!-- Publish on the FILE SYSTEM -->
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<!-- Publish on AZURE: Web Deploy -->
<CopyAllFilesToSingleFolderForMSDeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForMSDeployDependsOn);
</CopyAllFilesToSingleFolderForMSDeployDependsOn>
</PropertyGroup>

Related

Publish to Azure doesn't update files in App_Data

My ASP.Net Core app has an App_Data folder located under the project root:
(As I recall -- I may be mistaken -- I had to manually create that folder in the project. The template didn't give it to me automatically.)
My problem is that changes to the files in the App_Data folder are not pushed to Azure when I publish my project. I'm using VS Pro 2019.
When I first published the project, the App_Data folder and its contents were pushed to Azure. But, as I said, changes are ignored.
Here's the larger issue that I don't understand: Apparently, the App_Data folder is special. At least, it's got an entry in the publish profile. And I've seen lots of questions and uninformed answers about difficulties publishing (or not publishing) files that live in this magic folder. But I've never seen anything close to official documentation that talks about this bit of magic.
Here is my publish profile:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<ResourceId>/subscriptions/xxx/resourceGroups/Production/providers/Microsoft.Web/sites/xxx</ResourceId>
<ResourceGroup>Production</ResourceGroup>
<PublishProvider>AzureWebSite</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>http://xxx.azurewebsites.net</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>xxx</ProjectGuid>
<MSDeployServiceURL>xxx.scm.azurewebsites.net:443</MSDeployServiceURL>
<DeployIisAppPath>xxx</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>$xxx</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
<InstallAspNetCoreSiteExtension>False</InstallAspNetCoreSiteExtension>
<TargetFramework>netcoreapp2.2</TargetFramework>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>
</PropertyGroup>
</Project>
and here is my project file (edited for brevity):
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<UserSecretsId>aspnet-xxx</UserSecretsId>
<ApplicationInsightsResourceId>/subscriptions/xxx/resourcegroups/xxx/providers/microsoft.insights/components/xxx</ApplicationInsightsResourceId>
<ApplicationInsightsAnnotationResourceId>/subscriptions/xxx/resourcegroups/MyIndigoHealth/providers/microsoft.insights/components/xxx</ApplicationInsightsAnnotationResourceId>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TypeScriptToolsVersion>3.1</TypeScriptToolsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.6.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />
<PackageReference Include="Neleus.DependencyInjection.Extensions" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Areas\Identity\Services\" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
</Project>
According to the official documentation:
The Content item list contains files that are published in addition to
the build outputs. By default, files matching the pattern wwwroot/**
are included in the Content item.
The implication (not clearly stated) is that ONLY build outputs and wwwroot/** are published.
Later in the same documentation, they give examples (without explanation) of markup that adds additional files to the set of files being published. Based on those examples, I cooked up this markup. Adding this to the project (csproj) file causes changed files in the App_Data folder to be published:
<ItemGroup>
<DotnetPublishFiles Include="App_Data/**/*">
<DestinationRelativePath>App_Data/%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</DotnetPublishFiles>
</ItemGroup>
This still leaves a couple of related mysteries:
What does the <ExcludeApp_Data> element really do?
Apparently, the initial Publish (from Visual Studio) pushes the App_Data folder to the server. Why does this happen, when experimentation and the above-referenced documentation says that subsequent attempts to publish ignore the App_Data folder (and, indeed, any folder outside of wwwroot)?
If you right click your web project and select Publish > Settings > File Publish Options, then uncheck "Exclude files from the App_Data folder" what happens?

Is there a pubxml setting to delete folder on production prior to publishing using Visual studio

I am deploying visual studio project that contains Angular 5 application that is built in dist subfolder. Because dist subfolder is not a part of the project, I am copying it using the publishing profile settings (in .pubxml file):
<Target Name="CustomCollectFiles">
<Message Text="=== CustomCollectFiles ===" Importance="high" />
<ItemGroup>
<_CustomFiles Include="dist\**\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>dist\%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
This works fine the first time but on subsequent deployments the dist folder doesn't get updated. I thought of deleting it first before publishing so it's updated every time but I can't find the xml tag/setting for that.
Is there a setting/tag to delete the folder dist on production prior to publishing?

MSDeploy skip rules when using MSBuild PublishProfile with Visual Studio 2012

I'm trying to use WebDeploy to publish a website using custom MSDeploy skip rules and a publish profile saved in Visual Studio 2012.
I have the publish profile working from the command line, but the skip rule to skip deleting a folder isn't working.
I have an ErrorLog subfolder in my web app with a web.config file inside it to set the proper folder permissions. Without any skip rules, the ErrorLog folder and web.config file are published normally, but all existing error log files in the folder on the server are deleted on publish.
Error with <SkipAction>Delete</SkipAction>
When I add a custom skip rule to my wpp.targets file, the skip rule is no longer accepting a value for the <SkipAction> element. If I set <SkipAction>Delete</SkipAction>, I get the following error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4377,5): error : Web deployment task failed. (Unrecognized skip directive 'skipaction'. Must be one of the following: "objectName," "keyAttribute," "absolutePath," "xPath," "attributes.<name>.") [C:\inetpub\wwwroot\My.Website\My.Website\My.Website.csproj]
If I simply omit the <SkipAction> element, the ErrorLog folder is deleted when it would normally be published.
If I set <SkipAction></SkipAction>, again, the ErrorLog folder is deleted on publish.
If I set <KeyAttribute>Delete</KeyAttribute>, then ErrorLog and the web.config file are published normally.
My understanding is that in order to use custom skip rules, you need to call MSBuild from the command line instead of publishing from within VS 2012. I'd still like to use my saved publishing profiles, however, and I understand that's now possible as of VS 2012.
My MSBuild command line:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe My.Website.sln /p:Configuration=Release;DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"
My.Website.wpp.targets:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipErrorLogFolder1">
<SkipAction></SkipAction>
<KeyAttribute>Delete</KeyAttribute>
<ObjectName>dirPath</ObjectName>
<AbsolutePath>$(_Escaped_WPPAllFilesInSingleFolder)\\ErrorLog$</AbsolutePath>
<XPath></XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
</Project>
My MSBuild output showing the custom skip rule, but still deleting the files:
GenerateMsdeployManifestFiles:
Generate source manifest file for Web Deploy package/publish ...
AddCustomSkipRules:
Adding Custom Skip Rules
MSDeployPublish:
Start Web Deploy Publish the Application/package to http://testserver.domain.com/MSDEPLOYAGENTSERVICE ...
Starting Web deployment task from source: manifest(C:\inetpub\wwwroot\My.Website\My.Website\obj\Release\Package\My.Website.SourceManifest.xml) to Destination: auto().
Deleting filePath (MyWeb/ErrorLog\test.txt).
Updating setAcl (MyWeb/).
Updating setAcl (MyWeb/).
Updating filePath (MyWeb/ErrorLog\Web.config).
Updating filePath (MyWeb/Web.config).
Updating setAcl (MyWeb/).
Updating setAcl (MyWeb/).
Successfully executed Web deployment task.
Publish is successfully deployed.
Edit: It turns out you are right: the skip directive is ignored when executed from Visual Studio.
Fortunately, there's a workaround.
What you want is this:
<!-- Skip the deletion of any file within the ErrorLog directory -->
<MsDeploySkipRules Include="SkipErrorLogFolder1">
<SkipAction>Delete</SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>ErrorLog</AbsolutePath>
</MsDeploySkipRules>
In addition, you need to prevent VS from using the UI-task (which appears to contain a bug regarding the skip rules). You can do this by declaring the following in your wpp.targets or pubxml:
<PropertyGroup>
<UseMsDeployExe>true</UseMsDeployExe>
</PropertyGroup>
I've tested this locally and I can confirm that it works as desired: the additional file is updated but no files in the directory are deleted.
For reference, here is my complete .wpp.targets file with working skip rule to skip deleting the ErrorLog folder and custom ACLs to make the ErrorLog folder writable on the server.
As of VS 2012 Update 3, this only works when publishing with MSBuild from the command line with the DeployOnBuild=true;PublishProfile="Test Server - Web Deploy" options passed to MSBuild. This will not work when publishing from within VS.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseMsdeployExe>true</UseMsdeployExe> <!-- Required for the MSDeploySkipRules to work -->
<DeployManagedPipelineMode>Integrated</DeployManagedPipelineMode>
</PropertyGroup>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>
$(AfterAddIisSettingAndFileContentsToSourceManifest);
AddCustomSkipRules;
</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipErrorLogFolder">
<SkipAction>Delete</SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>ErrorLog</AbsolutePath>
<XPath></XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>
$(AfterAddIisSettingAndFileContentsToSourceManifest);
SetCustomACLs;
</AfterAddIisSettingAndFileContentsToSourceManifest>
<AfterAddDeclareParametersItemsForContentPath>
$(AfterAddDeclareParametersItemsForContentPath);
SetCustomAclParameters;
</AfterAddDeclareParametersItemsForContentPath>
</PropertyGroup>
<Target Name="SetCustomACLs">
<Message Text="Setting Custom ACLs" />
<ItemGroup>
<!--Make sure the application pool identity has write permission to the download folder-->
<MsDeploySourceManifest Include="setAcl"
Condition="$(IncludeSetAclProviderOnDestination) And Exists('$(_MSDeployDirPath_FullPath)\ErrorLog')">
<Path>$(_MSDeployDirPath_FullPath)\ErrorLog</Path>
<setAclAccess>Write</setAclAccess>
<setAclResourceType>Directory</setAclResourceType>
<AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
</MsDeploySourceManifest>
</ItemGroup>
</Target>
<Target Name="SetCustomAclParameters">
<Message Text="Setting Custom ACL Parameters" />
<EscapeTextForRegularExpressions Text="$(_MSDeployDirPath_FullPath)">
<Output TaskParameter="Result" PropertyName="_EscapeRegEx_MSDeployDirPath" />
</EscapeTextForRegularExpressions>
<ItemGroup>
<MsDeployDeclareParameters Include="Add write permission to ErrorLog folder"
Condition="$(IncludeSetAclProviderOnDestination) and Exists('$(_MSDeployDirPath_FullPath)\ErrorLog')">
<Kind>ProviderPath</Kind>
<Scope>setAcl</Scope>
<Match>^$(_EscapeRegEx_MSDeployDirPath)\\ErrorLog$</Match>
<Description>Add write permission to ErrorLog folder</Description>
<DefaultValue>Default Web Site/ErrorLog</DefaultValue>
<Value>$(DeployIisAppPath)/ErrorLog</Value>
<Tags>Hidden</Tags>
<Priority>$(VsSetAclPriority)</Priority>
<ExcludeFromSetParameter>True</ExcludeFromSetParameter>
</MsDeployDeclareParameters>
</ItemGroup>
</Target>
</Project>
Another approach is to avoid the SkipAction tag, I've successfully used this setup directly from VS 2013:
<Target Name="AddCustomSkipRules"
AfterTargets="AddIisSettingAndFileContentsToSourceManifest">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipMedia">
<objectName>dirPath</objectName>
<absolutePath>media</absolutePath>
</MsDeploySkipRules>
<MsDeploySkipRules Include="SkipUpload">
<objectName>dirPath</objectName>
<absolutePath>upload</absolutePath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
Only caveat as far as I can tell is that, it will ignore both update, delete and add operations.
After many hours looking through the net. i created this file as {myprojectname}.wpp.targets under the site root folder. it works when publishing with visual studio. the media folder is ignored. i am using VS 2010.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseMsdeployExe>true</UseMsdeployExe>
<!-- Required for the MSDeploySkipRules to work -->
<DeployManagedPipelineMode>Integrated</DeployManagedPipelineMode>
</PropertyGroup>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>
$(AfterAddIisSettingAndFileContentsToSourceManifest);
AddCustomSkipRules;
</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules - WPP Targets 2" />
<ItemGroup>
<MsDeploySkipRules Include="SkipErrorLogFolder">
<SkipAction>Delete</SkipAction>
<ObjectName>dirPath</ObjectName>
<AbsolutePath>media</AbsolutePath>
<XPath></XPath>
<Apply>Destination</Apply>
</MsDeploySkipRules>
</ItemGroup>
</Target>
</Project>
I think the problem is in incorrect AbsolutePath. It should be a regular expression to match file or folder. so it should be properly escaped. Below is the sample which worked for me (I wanted to skip removal of app_offline.htm to make delivery part of larger deployment)
<PropertyGroup>
<PackageUsingManifestDependsOn>$(PackageUsingManifestDependsOn);AddCustomSkipRules</PackageUsingManifestDependsOn>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<ItemGroup>
<MsDeploySkipRules Include="SkipAppOfflineOnDeploy">
<SkipAction></SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>app_offline\.htm</AbsolutePath>
<Apply>Destination</Apply>
<XPath></XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
Works for me: My Full prepprod.pubxml file in my App_Data/PublishProfiles folder in my web solution. Web Deploy no longer deletes files out of the cachefiles folder on webdeploy from VS 2015. The first PropertyGroup was auto-generated by using the web publishing gui in Visual Studio. I added the second PropertyGroup, and the Target section from previous comments.
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Production</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>{masked}</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<MSDeployServiceURL>{masked}</MSDeployServiceURL>
<DeployIisAppPath>{masked}</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<MSDeployUseChecksum>true</MSDeployUseChecksum>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>{masked}</UserName>
<_SavePWD>True</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="">
</Objects>
</PublishDatabaseSettings>
<ExcludeFilesFromDeployment>packages.config;*.bat;*.sln;*.suo,*.p4ignore</ExcludeFilesFromDeployment>
<ExcludeFoldersFromDeployment>packages;cachefiles;.ebextensions</ExcludeFoldersFromDeployment>
</PropertyGroup>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>
$(AfterAddIisSettingAndFileContentsToSourceManifest);
AddCustomSkipRules;
</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipcachefilesFolder">
<objectName>dirPath</objectName>
<absolutePath>cachefiles</absolutePath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
</Project>
This worked for me in vs 2015, website project type:
<!--Added inside existing <ProjectGroup> tag-->
<AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>
<!--Added new ProjectGroup tag inside <Project></Project>-->
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
</PropertyGroup>
<!--Added inside existing <Project> tag at the bottom-->
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipConfigFolder">
<SkipAction></SkipAction>
<!--<KeyAttribute>Delete</KeyAttribute>-->
<ObjectName>dirPath</ObjectName>
<AbsolutePath>App_Data\\Composite\\Logfiles</AbsolutePath>
<XPath>
</XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>

Web Setup replacement to create MSI in VS2012?

I have a project in VS2010 that uses Web Setup projects for deployment. I'm now looking into migrating it to VS2012 and have to find a replacement setup routine.
The requirements I have:
One-step build to create a deploy package/installer on a dev machine.
Setup program/routine that can be run on the server - without Visual Studio available.
No direct interaction between Visual Studio and the server. I have to copy the setup files over through an RDP session.
Setup of web applications (MVC) and Windows Services, preferably bundled in one single installer (new requirement currently not solve din Web Setup project).
Possibility to run EF Migrations as part of setup (currently done through a custom action).
Where should I start? Should I look into the improved publishing features in VS2012? Should I look at Wix? Something else?
Looking deeper into Visual Studio 2012 and trying to work with it the way it was intended, instead of against it, we ended up using web deploy packages. It doesn't create an MSI file, but instead a zip file that can be easily imported into IIS on the target machine.
The Windows service project was added as a reference to the web site project. That way the binaries for the service are included in the bin directory of the web site. The migrate.exe file from Entity framework was added as a link from the bin directory which means it is deployed too.
Finally we added a project.wpp.targets file to the project that runs the required commands to install and start the service and to get the service's config file included in the deploy. This worked for us, but is not really that elegant (e.g. the install paths of the site for different configurations is hard coded).
The project.wpp.targets file:
<?xml version="1.0" encoding="utf-8" ?>
<!--
*** WARNING ***
This file is cached by visual studio and changes won't take effect until
visual studio is restarted. When editing this file, it is better to run the
build step for packaging from the command line (a VS command prompt).
There are some problems with dependencies not being correctly identified that
way, but at least the archive.xml file can be verified from the command prompt.
msbuild orderportal.csproj /t:package /p:Configuration=SysTest /p:DeployOnBuild=true;DeployTarget=Package
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeRunMigrations>TRUE</IncludeRunMigrations>
<AfterAddIisSettingAndFileContentsToSourceManifest Condition="'$(AfterAddIisSettingAndFileContentsToSourceManifest)'==''">
$(AfterAddIisSettingAndFileContentsToSourceManifest);
RunMigrations;
ServiceInstall;
</AfterAddIisSettingAndFileContentsToSourceManifest>
<IncludeServiceInstall>TRUE</IncludeServiceInstall>
<BeforeAddContentPathToSourceManifest Condition="'$(BeforeAddContentPathToSourceManifest)' == ''">
$(BeforeAddContentPathToSourceManifest);
ServiceUnInstall;
</BeforeAddContentPathToSourceManifest>
<DeploymentDir Condition="'$(Configuration)'=='SysTest' AND '$(DeploymentDir)'==''">c:\inetpub\wwwroot\SysTest\</DeploymentDir>
<DeploymentDir Condition="'$(Configuration)'=='IntTest' AND '$(DeploymentDir)'==''">c:\inetpub\wwwroot\IntTest\</DeploymentDir>
<DeploymentDir Condition="'$(Configuration)'=='Prod' AND '$(DeploymentDir)'==''">c:\inetpub\wwwroot\</DeploymentDir>
<CopyAllFilesToSingleFolderForPackageDependsOn>
IncludeServicesAppConfig;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="RunMigrations" Condition="'$(IncludeRunMigrations)' == 'TRUE'">
<Message Text="Adding migration running"/>
<ItemGroup>
<MsDeploySourceManifest Include="runCommand">
<path>$(DeploymentDir)bin\migrate.exe /startupdirectory:$(DeploymentDir)bin Topsi.Core.dll /startUpConfigurationFile:$(DeploymentDir)web.config</path>
<waitAttempts>1</waitAttempts>
<waitInterval>60000</waitInterval>
<dontUseCommandExe>true</dontUseCommandExe>
<AdditionalProviderSettings>waitInterval;waitAttempts;dontUseCommandExe</AdditionalProviderSettings>
</MsDeploySourceManifest>
</ItemGroup>
</Target>
<Target Name="ServiceUnInstall" Condition="'$(IncludeServiceInstall)' == 'TRUE'">
<Message Text="Adding service uninstall" />
<ItemGroup>
<MsDeploySourceManifest Include="runCommand">
<path>net stop "Topsi Schedule Service $(Configuration)"</path>
<waitAttempts>1</waitAttempts>
<waitInterval>60000</waitInterval>
<dontUseCommandExe>true</dontUseCommandExe>
<AdditionalProviderSettings>waitInterval;waitAttempts;dontUseCommandExe</AdditionalProviderSettings>
</MsDeploySourceManifest>
<MsDeploySourceManifest Include="runCommand">
<path>C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe /u $(DeploymentDir)bin\Topsi.Services.exe</path>
<waitAttempts>1</waitAttempts>
<waitInterval>60000</waitInterval>
<dontUseCommandExe>true</dontUseCommandExe>
<AdditionalProviderSettings>waitInterval;waitAttempts;dontUseCommandExe</AdditionalProviderSettings>
</MsDeploySourceManifest>
</ItemGroup>
</Target>
<Target Name="ServiceInstall" Condition="'$(IncludeServiceInstall)' == 'TRUE'">
<Message Text="Adding service install"/>
<ItemGroup>
<MsDeploySourceManifest Include="runCommand">
<path>C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe $(DeploymentDir)bin\Topsi.Services.exe</path>
<waitAttempts>1</waitAttempts>
<waitInterval>60000</waitInterval>
<dontUseCommandExe>true</dontUseCommandExe>
<AdditionalProviderSettings>waitInterval;waitAttempts;dontUseCommandExe</AdditionalProviderSettings>
</MsDeploySourceManifest>
<MsDeploySourceManifest Include="runCommand">
<path>net start "Topsi Schedule Service $(Configuration)"</path>
<waitAttempts>1</waitAttempts>
<waitInterval>60000</waitInterval>
<dontUseCommandExe>true</dontUseCommandExe>
<AdditionalProviderSettings>waitInterval;waitAttempts;dontUseCommandExe</AdditionalProviderSettings>
</MsDeploySourceManifest>
</ItemGroup>
</Target>
<Target Name="IncludeServicesAppConfig">
<ItemGroup>
<_CustomFiles Include="..\Services\bin\$(Configuration)\Topsi.Services.exe.config">
<DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</_CustomFiles>
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
</Project>

Visual Studio. Publish project from command line

Is there a way to publish a web project in MS Visual Studio 2010 using CLI? I use DevEnv.exe /Build to build a project and it works fine, but I could not find option to Publish a project.
One other thing I want to mention. I am trying to publish web project NOT to the IIS directly. I have a location where I publish several projects and then build them automatically into NSIS bundle to be deployed.
From ASP.NET Web Deployment using Visual Studio: Command Line Deployment, you can use
msbuild myproject.csproj /p:DeployOnBuild=true /p:PublishProfile=MyPublishProfile
where MyPublishProfile is the profile name that you've already set up somewhere
What works best is to add following target to the project file:
<Target Name="AfterBuild">
<Message Text="Copying to Deployment Dir:" />
<Copy SourceFiles="#(Content)" DestinationFolder="..\XXX\%(Content.RelativeDir)" />
<CreateItem Include="$(OutputPath)\*">
<Output TaskParameter="Include" ItemName="Binaries"/>
</CreateItem>
<Copy SourceFiles="#(Binaries)" DestinationFolder="..\XXX\bin" />
</Target>
This way, whenever project got build (from command line or from IDE) it automatically get deployed to specified folder. Thank you everybody for pointing me to right direction.
The /t:publish switch is for ClickOnce applications only, it's not applicable to web projects. Hence the error saying it's unpublishable. :)
#RobKent As https://stackoverflow.com/a/2775437/21233364
using
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release' ">
<Message Text="Copying to Deployment Dir:" />
<Copy SourceFiles="#(Content)" DestinationFolder="..\XXX\%(Content.RelativeDir)" />
<CreateItem Include="$(OutputPath)\*">
<Output TaskParameter="Include" ItemName="Binaries"/>
</CreateItem>
<Copy SourceFiles="#(Binaries)" DestinationFolder="..\XXX\bin" />
</Target>
you can have publish only on release compiling.

Resources