how to change default siteName and its physical path using msdeploy - msbuild

Here i'm trying to automate publish the package for a web application to publish IIS on a remote server.
Following things are done to make the package.
Publish.proj.xml file:
<Project ToolsVersion="4.0" DefaultTargets="Publish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectSolutionFile>Test.sln</ProjectSolutionFile>
<Configuration>Release</Configuration>
</PropertyGroup>
<ItemGroup>
<ProjectToBuild Include="$(ProjectSolutionFile)">
<Properties>DeployOnBuild=true;Configuration=$(Configuration)</Properties>
</ProjectToBuild>
</ItemGroup>
<Target Name="Publish">
<MSBuild Projects="#(ProjectToBuild)"/>
</Target>
</Project>
If i pass this Publish.proj.xml file to msbuild. it'll build the solution and will create the package with below included things,
1. PackageTmp (folder)
2. Test.deploy.cmd
3. Test.deploy.SetParameters.xml
4. Test.SourceManifest.xml
5. Test.zip
Test.SetParameters.xml
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<setParameter name="IIS Web Application Name" value="Default Web Site/Test_deploy" />
</parameters>
Test.SourceManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<sitemanifest>
<IisApp path="C:\Release\Package\PackageTmp" managedRuntimeVersion="v4.0" />
<setAcl path="C:\Release\Package\PackageTmp" setAclResourceType="Directory" />
<setAcl path="C:\Release\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" />
</sitemanifest>
Now, i'm trying to install this package in a remote server to publish the package using below command,
SalesCatalogue.deploy.cmd /y /M:https://RemoteServer:8172/MSDeploy.axd /u:"Test" /p:Test123 -allowUntrusted /A:basic
It has created new virtual directory in IIS under Default Web Site->Test_deploy and package files are deployed in C:\inetpub\wwwroot\Test_deploy folder.
My requirement is, Virtual directory name, applicatio Pool, destination physical deployment path are should be configurable. So that I can provide name whatever for virtual directory, can select desire application pool and can deploy in different path if required.
How can i achieve this? Any one can suggest me.
Thanks in advance.

Related

Identity works fine on localhost but having errors on server

I am using .Net Core MVC with built-in authorization for individual user accounts.
Registration and login works fine when I run it locally but when I uploaded it on Smarterasp and tried to register I got an error saying :
An error occurred while processing your request.
This is my publishing profile
<?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 https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>website.com</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ProjectGuid>501f4fbc-faa5-4f41-859b-177881cbb611</ProjectGuid>
<SelfContained>false</SelfContained>
<MSDeployServiceURL>https://website.com:8172/MsDeploy.axd?site=coinmaniabot-001-site1</MSDeployServiceURL>
<DeployIisAppPath>sitename</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<UserName>coinmaniabot-001</UserName>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
<_SavePWD>False</_SavePWD>
</PropertyGroup>
</Project>

How exclude certain appsettings files from publishing

I have asp.net core 2 application. Based on documentation i have created .pubxml file for my development environment. I am using web deployment (remote agent) to deploy the web package to target web server. On our build server where, jenkins is installed, i run the following command to build & deploy
D:\Jenkins\myproject\workspace\myapplication\Src\Api>dotnet publish Api.csproj /p:PublishProfile=development.pubxml
It builds and deploys the application successfully to target web server.
However my application has multiple appsettings files specific to each environment. For example appsettings.json, appsettings.development.json, appsettings.staging.json and appsettings.production.json The deployment process deploys all the appsettings files to web server. (in this case to development web server)
How do i only include environment specific appsettings file? (in this case i want to deploy appsettings.json, appsettings.development.json but not other 2 files)
You can add <ItemGroup> definitions to your publish profiles (.pubxml files) containing update statements for the files.
For example if the publish profile is named Production.pubxml/ Staging.pubxml according to the environment, you can add this item group to the root <Project> xml node:
<ItemGroup>
<Content Update="appsettings.*.json" CopyToPublishDirectory="Never" />
<Content Update="appsettings.$(MSBuildThisFileName).json" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
I could handle this with the following *.pubxml:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
.
.
.
</PropertyGroup>
<ItemGroup>
<Content Update="appsettings.Development.json">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.TestBed.json">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

Execute .bat file at end of VS2017 Asp.Net Core publish action?

In Visual Studio 2017 when publishing an Asp.Net Core Website using the File System publish method I want to trigger the execution of a .bat file after the publish operation copied the files to the output directory.
I have learned that the settings for the publish operation are stored by Visual Studio in the project's Properties/PublishProviles directory in a .pubxml file. So in may case the file is FolderProfile.pubxml and it currently looks like this:
<?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 https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>net461</PublishFramework>
<ProjectGuid>f58b5ca0-8221-4c97-aa6d-7fba93a3abeb</ProjectGuid>
<publishUrl>C:\inetpub\wwwGiftOasisResponsivePublished</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
Based on the comments in the .pubxml file and additional research, it's my understanding this file is essentially an msbuild file and ultimately msbuild is used to perform the publish operation. msbuild files seem very flexible but more than a little complicated. I'm really struggling with this one.
If I had a batch file in the root of my project called finishPub.bat, how could I modify the above .pubxml file to cause the execute of the finishPub.bat file after the website has been copied to the output folder?
You can amend your publish profile with a custom target:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
...
</PropertyGroup>
<Target Name="ExecuteBatAfterPublish" AfterTargets="AfterPublish">
<Exec Command="example.bat" WorkingDirectory="$(publishUrl)" />
</Target>
</Project>

How to get jspm/webpack/browserify/requirejs bundling working with msdeploy?

I currently use jspm but the same issue applies with any other build-time bundling tool. I can't figure out how to get these to play well with msdeploy.
Here's the issue:
I run jspm to produce one or more bundle files (one for each "chain" that I want).
My application uses System.import (or require or just a script tag) to start these loading.
If I were to deploy everything to a directory and xcopy from there to the deployment server everything is copacetic. However, our devops team prefers to deploy using msdeploy. For this I'm supposed to point it at a csproj. If I do this then how does msdeploy know to deploy the generated bundles?
You have to create an MSBuild project to accomplish this - one which hooks into the MSDeploy pipeline. I've provided a sample (one I'm currently using for a project) below; I'm likely going to release this as a Nuget package (along with some other MSBuild scripts that were written to take advantage of npm, jspm, and gulp).
The props file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
FrontendDeploymentFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
</Project>
The targets file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="FrontendDeploymentFiles">
<ItemGroup>
<_CustomFiles Include="dist\**\*" />
<_CustomFiles Include="jspm_packages\**\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>%(RelativeDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
</Project>
This isn't exactly a drop-in for you as you're bundling your files, but the takeaway here is that you can define a glob pattern for your copy methods. Replace jspm_packages with whatever your bundles are (as the scripts I've provided are only for publishing to a development environment) and you should be good.
Hope this is helpful to anyone else who runs into this issue.

Working directory issue when importing msbuild file in another msbuild file

I am trying to specify some additional targets/tasks to an msbuild file by extending an existing msbuild file (a web applicartion .csproj file). The idea is to put configuration specific tasks in this "extended ms build file" and use this file in our build server (TeamCity). The way I tried to solve it at first was to add a folder "msbuildscripts" to my web project and put the extended ms build file there:
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="../My.Web.csproj" />
...more stuff...
</Project>
and then build this file using something like:
c:\myweb\msbuild.exe msbuildscripts/extended.msbuild.file.xml
Now, this wont work because when importing the original ms build file, that csproj file will be "executed" in the "wrong" folder (msbuildscripts), and the csproj-build-file wont find any of its referenced folders/items.
Is there any way to tell msbuild.exe to use a specific working directory? I know it is possible to solve this problem using an execute task, but that doesnt seem like a good solution.
Use MSBuild task like this:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="MyBuild">
<ItemGroup>
<ProjectToBuild Include="../My.Web.csproj" />
</ItemGroup>
<Target Name="MyBuild">
<MSBuild Targets="Build" Projects="#(ProjectToBuild)"></MSBuild>
</Target>
</Project>