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>
Related
I am using asp.net core with NLog, here is the NLog target config
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/logs/logfile-${shortdate}.txt"
keepFileOpen="true"
encoding="utf-8" />
<target xsi:type="Null" name="blackhole" />
When I run from Visual Studio (F5), asp.net create logs folder and generate file like above configuration.
But when I deploy to Azure Webapp by Azure DevOps, it couldn't generate log file.
Is there anyway to fix this issue?
What happens if you change the NLog.config to be included in publish. Update csproj-file:
<None Update="nlog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
The special one is CopyToPublishDirectory
I have a shared.{Environment}.json file that is added as linked files in several .Net core 2.1 projects. When project is build or published file gets copied to output directory, in case of release its fine but on debug it doesn't work as when project run it looks up for that file in project directory not in output directory.
Whats the proper way to solve this issue for both debug and publish?
For linked files, it will not exist under the project directory.
For a workaround, you could try to copy the file with task in csproj like below:
<ItemGroup>
<Content Include="..\MVCPro\shared.{Environment}.json">
<Link>shared.{Environment}.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="..\MVCPro\shared.{Environment}.json" DestinationFolder=".\" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />
</Target>
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.
I'm using CSLA framework with dot net core 2.0.
When I do publish (dotnet publish -c Release -r ...) using Release configuration additional folders (tr, sv, sr) to name few of them, contains Csla.Resources.dll and they are copied in output publish folder ( ~/bin/Release/netcoreapp2.0/centos.7-x64/publish).
How to exclude these folders (with the file) or delete them from publish folder, once when dotnet publish finish executing?
Note
File "Csla.resources.dll" doesn't exist before deploy process start.
It will be generated when dotnet publish started.
How to exclude these folders (with the file) or delete them from publish folder, once when dotnet publish finish executing?
According to the below document:
https://learn.microsoft.com/en-us/aspnet/core/publishing/web-publishing-vs?tabs=aspnetcore2x
You can use CopyToPublishDirectory="Never" to excluding files and folders:
<ItemGroup>
<Content Update="wwwroot/content/**/*.*" CopyToPublishDirectory="Never" />
</ItemGroup>
If you don't know where exactly those files are, you can use msbuild to exclude all folders where one is found by adding this to the csproj file:
<ItemGroup>
<_CslaResourcesAssemblies Include="**/Csla.Resources.dll" />
<Content Update="#(_CslaResourcesAssemblies->'%(RecursiveDir)**')" CopyToPublishDirectory="Never" />
</ItemGroup>
I have a console project in my solution.
Now I want that exe of that project should be added to my main project post deployment using web deploy.
How can I achieve that?
Regards,
Gautam
There are two high level solutions for this:
Option 1: Copy the file into App_Data
You can copy the exe into the App_Data folder as part of a post build event or as part of the script below. It's your choice.
Now that it's there, we have another problem. The WPP only includes files that are part of the project when it deploys. To get around this, you can create a WebProjectName.wpp.targets file to the root of the web application with the following contents:
<Project>
<PropertyGroup>
<BeforeAddContentPathToSourceManifest>
$(BeforeAddContentPathToSourceManifest);
IncludeExeInDeployment;
</BeforeAddContentPathToSourceManifest>
</PropertyGroup>
<Target Name="IncludeExeInDeployment">
<Copy SourceFiles="$(WebPublishPipelineProjectDirectory)\App_Data\Console\*"
TargetFolder="$(WPPAllFilesInSingleFolder)\App_Data\Console" />
</Target>
</Project>
(You could just as easily skip the interim step and copy the exe from it's original home into the $(WPPAllFilesInSingleFolder) folder)
Option 2: Include the exe as a separate provider
This one requires a bit more understanding of msdeploy, but gives you the option to deploy the exe wherever you want on the target server.
Basically it involves adding an additional dirPath provider in the deployment. Again, add a wpp.targets file in the root:
<Project>
<PropertyGroup>
<AfterAddContentPathToSourceManifest>
$(AfterAddContentPathToSourceManifest);
IncludeConsoleAppInDeployment;
</AfterAddContentPathToSourceManifest>
</PropertyGroup>
<Target Name="IncludeConsoleAppInDeployment">
<ItemGroup>
<MsDeploySourceManifest Include="dirPath">
<Path>full path to console directory</Path>
</MsDeploySourceManifest>
</ItemGroup>
</Target>
</Project>
You'll also need to replace the path in your pubxml to specify where the exe will go on the far end:
<ItemGroup>
<MsDeploySetParameters Include="ConsoleAppPath">
<Kind>ProviderPath</Kind>
<Scope>dirPath</Scope>
<Match>regex that matches console directory</Match>
<Value>Path to console application on remote server</Value>
</MsDeploySetParameters>
</ItemGroup>