Transform external config in a web role - azure

Can slowcheetah transform an external config file in an azure web role? e.g. I have logging info in log4net.config. But the transformed version does not get created when packaged.

I did not manage to get slowCheetah working in my Azure solution.
One alternative you can use is to create complete config files for each environment - e.g. :
log4net.debug.config
log4net.release.config
and copy the contents of these into the log4net.config at buildtime depending on the build configuration chosen.
This is done by adding a build target to your csproj file like so:
<Target Name="BeforeBuild">
<Delete Files="$(ProjectDir)log4net.config" />
<Copy SourceFiles="$(ProjectDir)log4net.$(Configuration).config"
DestinationFiles="$(ProjectDir)log4net.config" />
</Target>
(you may have to modify the paths in the script depending on where in the solution your config files are)
You can find more information on MSBuild and manipulating your .csproj file here and here

Related

NLog - Configure log file name from appsettings in web.config

What i want is to pull the Log File path from my Web.config appsettings section.
The scenario is that, the deployment team would replace all the files while deployment except the web.config. Hence even if i set up my NLog Config File, it would be replaced in the next deployment and all my settings would be lost.
Is there a way that I could read the appsettings from my config and use it to set my log file path?
<target xsi:type="File" name="FileLog" fileName="PULL_LOG_PATH_FROM_WEB_CONFIG/${shortdate}.log">
Use NLog.Extended and use
${appsetting:key1}.
So
<target xsi:type="File" name="FileLog" fileName="${appsetting:key1}/${shortdate}.log" />
See docs for ${appsetting}
update: this is currently only supported for ASP.NET and not for ASP.NET Core. See issue for ASP.NET Core: https://github.com/NLog/NLog/issues/2334

Include static files in Azure WebJob's publish-settings.json

Is it possible to specify in a WebJob's webjob-publish-settings.json file that a folder of static/flat files should be included?
Update:
As per #davidebbo's suggestion, I've tried modifying the .csproj file, but without success.
<Target Name="BeforeBuild">
<ItemGroup>
<Content Include="$(ProjectDir)\Templates\*.xslt" />
</ItemGroup>
</Target>
I've tried both BeforeBuild and AfterBuild, and with/without the $(ProjectDir) variable, but the folder never appears in the bin directory.
It is not something you can do using webjob-publish-settings.json. Instead, you can do this by setting the 'Copy to Output Directory' property of the relevant files to Copy always or Copy if newer.

Include files in MSBuild that are not part of project

I'm trying to create an automated build for my web application project.
We use a standard CMS project and have tweaked some parts of it. Only the tweaked files are part of our project, but I want to include the full CMS in the deployment package.
So I've created a custom .targets file to define a task to include the CMS files during the build:
<Target Name="GetCMSFiles">
<ItemGroup>
<!-- Include the CMS files into the package -->
<_CMSFiles Include="..\packages\CMSFiles\**\*" />
<FilesForPackagingFromProject Include="%(_CMSFiles.Identity)">
<DestinationRelativePath>
%(RecursiveDir)%(Filename)%(Extension)
</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<!-- VS2010 -->
<CopyAllFilesToSingleFolderForPackageDependsOn>
GetCMSFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<!-- VS2012 -->
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
GetCMSFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
This works fine, but the problem is that the files from our project do not get copied to the deployment folder. So in other words, it does not overwrite the files that already exist after I copied them with the GetCMSFiles task.
The way I see it there are two options:
Force the CopyAllFilesToSingleFolder to overwrite any existing files in the deployment folder.
Have a condition in the GetCMSFiles task to only include files that don't already exist in the project.
But I'm not sure whether this is possible and how to achieve this. Any ideas?

VS 2012 Publishing Profiles and Copy Files Using MSBuilld Commands

I've set up asp.net website on Azure with TFS online for source control using VS 2012. I'm trying to copy files using VS 2012 new publishings profiles and MSBuild. Reading this article Visual Studio 2012 Web Deployment Projects are Dead – Long Live Publishing Profiles, in which Doug says you can use build scripts in your publishing profile.
So I setup a test that works in my .csproj on my local build. I'm just simply copying the robots.txt file from the root directory to the css directory. Here is my test. I set my pubxml in the TFS Build Process template under process > 6. Publishing -- Azure Website, Web Deploy Pubish Profile.
<Target Name="AfterBuild">
<Copy SourceFiles="$(ProjectDir)robots.txt" DestinationFolder="$(ProjectDir)css\" />
</Target>
I dropped this Code into my my pubxml file and I get a big nothing. What am I doing wrong?
Is it possible to copy files afterbuild on Azure?
Additional Information
The log file contains these lines so I'm sure the publishing profile is running.
AfterBuild:
Creating directory "C:\a\src\...\css".
Copying file from "C:\a\src\...\robots.txt" to "C:\a\src\...\css\robots.txt".
Here are the build steps that Azure's default build template uses:
ValidateSolutionConfiguration:
PrepareForBuild:
CoreCompile:
_CopyFilesMarkedCopyLocal:
CopyFilesToOutputDirectory:
GenerateTargetFrameworkMonikerAttribute:
CoreCompile:
_CopyFilesMarkedCopyLocal:
CopyFilesToOutputDirectory:
_CopyWebApplicationLegacy:
ValidateGlobalPackageSetting:
CollectFilesFromIntermediateAssembly:
CollectFilesFromContent:
CollectFilesFromIntermediateSatelliteAssembliesWithTargetPath:
CollectFilesFromReference:
CollectFilesFromAllExtraReferenceFiles:
CollectFilesFrom_binDeployableAssemblies:
PipelineCollectFilesPhase:
ExcludeGeneratedDebugSymbol:
PreTransformWebConfig:
TransformWebConfigCore:
PostTransformWebConfig:
PreProfileTransformWebConfig:
PipelineTransformPhase:
ProcessPublishDatabaseSettings:
PreAutoParameterizationWebConfigConnectionStrings:
AutoParameterizationWebConfigConnectionStringsCore:
PostAutoParameterizationWebConfigConnectionStrings:
PipelineMsdeploySpecificTransformPhase:
ValidatePublishProfileSettings:
CopyAllFilesToSingleFolderForMsdeploy:
PipelineCopyAllFilesToOneFolderForMsdeploy:
Package:
GenerateMsdeployManifestFiles:
PackageUsingManifest:
GenerateSampleDeployScript:
PipelineDeployPhase:
AfterBuild:
So it looks like Azure packages all the files up during the "31. CopyAllFilesToSingleFolderForMsdeploy" step. It would appear that running copy during the AfterBuild step is to late. I moved the Copy command to the target "BeforeBuild" but the files are still not ending up in the CopyAllFilesToOneFolderForMsdeploy step.
Thanks to Sayed Ibrahim Hashimi for his article How to compress CSS/JavaScript before publish/package for helping me solve this.
It's possible to copy directly Package Temp Directory. I ended up adding this target to my publishing profile (pubxml) file. After the "CopyAllFilesTOSingleFolderForMsdeploy" step finishes this step will run which will copy a file from one part of the solution into the destinationfolder you specify.
<Target Name="AdditionalFilesForPackage" AfterTargets="CopyAllFilesToSingleFolderForMsdeploy">
<Copy SourceFiles="$(ProjectDir)robots.txt" DestinationFolder="$(_PackageTempDir)\css\" />
</Target>

Create folder inside debug or release con console application

i have a console application in vs2010 (C#) and in the project, i have a Folder added by me (right click on project.. add->folder) and i want that when i compile the application (debug or release), then the folder will be created (if not exists) in the debug or release directory.
Is that possible?
The console application is a daemon that access to a database and send emails with templates allocated in that folder.
I hope you can help me. Thanks!
There's no "automatic" way to get VS to create folders (other than the specified output folder) during a build, but there's two pretty easys ways to accomplish it.
Use a post-build event, which you set up in the Build Events tab of your project's properties. This is basically a batch file that you run after the build completes, something like this:
IF NOT EXIST $(OutDir)MySubFolder MKDIR $(OutDir)MySubFolder
XCOPY /D $(ProjectDir)MySubFolder\*.tmpl $(OutDir)MySubFolder
Use MSBuild's AfterBuild event. This is my preferred method, mostly because it integrates better with our automated build process, but it's a little more involved:
Right-click on your project node and Unload it
Right-click on the unloaded project node and Edit the file
Near the bottom is a commented-out pair of XML nodes. Uncomment the AfterBuild target and replace it with something like this:
<Target Name="AfterBuild">
<MakeDir Directory="$(OutDir)MySubFolder" Condition="!Exists('$(OutDir)MySubFolder')" />
<CreateItem Include="$(ProjectDir)MySubFolder\*.tmpl">
<Output TaskParameter="Include" ItemName="Templates" />
</CreateItem>
<Copy SourceFiles="#Templates" DestinationFolder="$(OutDir)MySubFolder" ContinueOnError="True" />
</Target>
Save the changes, close the .csproj file, then right-click and Reload the project.
I solve it, like this:
in the csproj:
<Target Name="AfterBuild">
<MakeDir Directories="$(OutDir)EmailTemplates" Condition="!Exists('$(OutDir)EmailTemplates')" />
<ItemGroup>
<Templates Include="$(ProjectDir)EmailTemplates\*.*" />
</ItemGroup>
<Copy SourceFiles="#(Templates)" DestinationFolder="$(OutDir)EmailTemplates" />
</Target>
Thank you for your help!

Resources