How to add extra files to the package that is generated by msbuild called by an Azure Resource Group Project in Visual Studio - azure

So I have a solution made up of a web project and an Azure Resource Group project much like what is described here: https://blogs.technet.microsoft.com/georgewallace/2015/05/10/deploying-a-website-with-content-through-visual-studio-with-resource-groups/
The issue I am having is that the web project needs to include some EXTRA files in its bin directory in order to function. Now through the normal package process on the web project itself I accomplish this by adding a custom target and hook into CopyAllFilesToSingleFolderforPackageDependsOn, like:
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="bin\SlimKIA.WebApi.xml" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin\SlimKIA.WebApi.xml</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
And when I right-click on the web project and say "publish" to, say, a file system, my file gets included. All is well and good.
The problem is that this does not happen when I deploy from the deployment project. I have an MsDeploy resource that does its own thing. I need to somehow do my CustomCollectFiles from within this project.
Anyone have any ideas as to how to accomplish this? Without this I am unable to automate the deployment of my solution to Azure.
Thanks!

On a whim I ended up doing this:
<PropertyGroup>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
The key being the CopyAllFilesToSingleFolderForMsdeployDependsOn instead of CopyAllFilesToSingleFolderForPackageDependsOn. Just changing this did the trick, which I guess triggered msdeploy to include the custom target.

Related

Bot Framework publish and deploy to Azure from VS 2019 - missing files

I wrote a C# web bot using external resources (.lg and .dialog files), which - as I think - are not deployed along with the code. I deploy from VS2019, right click and "publish / azure / Azure App Service (windows 10)" into an already existing app service.
Which are the worst that asks almost nothing, I cant see how I can add files to the publishment package. The bot wont work on azure portal, after several hours I found where are the log files, and see that it says cant open the .lg file because it is missing.
In the adaptive dialog constructor:
this.Generator = new TemplateEngineLanguageGenerator(Templates.ParseFile(Configuration["Dialog.Templates.Root"]));
in my appsettings.json:
"Dialog.Templates.Root": "Templates/root-dialog-templates.lg",
How can I add files to copy along during the deployment?
Thanks for any suggestion and help!
You can include something like this sample in your .csproj file, assuming your .lg, .dialog files are under the Dialogs folder
<ItemGroup>
<None Remove="Dialogs\**\*.lg" />
<None Remove="Dialogs\**\*.dialog" />
</ItemGroup>
<ItemGroup>
<Content Include="Dialogs\**\*.lg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Dialogs\**\*.dialog">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
This way you'll find the deployed files in the same folder relative to the project's content root, which is usually current directory.

How can I include additional files in an Azure cloud services package when using VSTS?

I have a solution with a web project in it and a cloud project for deploying that web project as a cspkg file to a cloud service. This all works fine. However, I have a file that i don't want in the web project but I do want deployed with the cspkg file into the cloud service.
We use VSTS to build and deploy things, and I haven't figured out how to include extra files in the package within this system. I tried a Copy Files step but that doesn't get the file into the package, it does get it into the artifacts though. I tried other things I found online, like the PipelineCollectFilesPhaseDependsOn injection technique, but nothing seems to work.
Is this possible, and if so, how can it be done?
The Azure deployment package file (CSPKG) file is zipped and encrypted, there isn’t the better way to add additional files (More details: Include/Exclude files when creating Azure package). But you can include the files in BeforeBuild target. For this way, you don’t need to include files to the web project.
For example:
Edit web project file (e.g. WebRole1.csproj)
Add BeforeBuild target before tag.
Code:
<Target Name="BeforeBuild">
<ItemGroup>
<Content Include="Files\TT.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Target>

Publish web project - MSBuild does not copy dependent projects' DLL which are not added reference to web project

My web application basically have three seperated projects:
A web project "MyWeb" which I want to publish to production environment
A Library project "MyBusiness" which define the Business layer's interfaces. This project is referenced by MyWeb project
Another Library project "MyBusinessImplementation" which contain the Business layer's implementation (concrete classes implement the
Business layer's interfaces).
To do Dependency Injection, my MyWeb project just add reference to the MyBusiness interfaces project, not the implementation (or else my web project is closely tied to the implementation, and also I can't prevent my developers from making a "new" object of a concrete class in my web project).
Without adding reference directly to the Business implementation project, when building the project, Visual Studio doesn't know to copy the implementation project's DLL into the web's bin folder, so I added this into MyWeb project file:
<PropertyGroup>
<BuildDependsOn>BuildDependentProjects;$(BuildDependsOn);</BuildDependsOn>
</PropertyGroup>
<ItemGroup>
<ProjectToBuild Include="$(SolutionDir)\MyBusinessImplementation\MyBusinessImplementation.csproj">
<Properties>Configuration=$(Configuration)</Properties>
</ProjectToBuild>
</ItemGroup>
<Target Name="AfterBuild">
<Copy SourceFiles="$(SolutionDir)\MyBusinessImplementation\bin\$(Configuration)\MyBusinessImplementation.dll" DestinationFolder="$(SolutionDir)\MyWebSite\bin"></Copy>
</Target>
<Target Name="BuildDependentProjects">
<MSBuild Projects="#(ProjectToBuild)" />
</Target>
The problem is, when I publish MyWeb project from Visual Studio 2012, or when I run
"MSBuild "MyWeb.jsproj" \T:Package \P:Configuration=Debug"
I see that the MyBusinessImplementation.dll is copied into MyWeb's bin folder of my working code directory but NOT in the published package directory.
I've also tried to change the DestinationFolder of the Copy task to an absolute path like "C:\abc" then I see the .dll file is copied successfully to the abc folder, but still not copied to my Package's web's bin folder.
It looks like you are missing a step of adding the copied item to the WebDeploy manifest and package before its deployed.
Check this post out for a great answer on how to include extra files to the package.
How do you include additional files using VS2010 web deployment packages?

AjaxMin not working on Azure site

I am using Microsoft's AjaxMin to minify javascript on my website, which is hosted by Azure. I am using a BuildTask to automatically minify javascript at run time. This build task is specified in the .csproj file.
The process is working on my local environment, however, it does not work when I deploy to my Azure site. The azure site throws 404: file not found errors, when i try to reference the minified version of .js files.
Is it possible to use build tasks on an Azure site? Is there anything I am missing? I have made sure not to include the .min.js files in source control as this (http://www.asp.net/ajaxlibrary/AjaxMinQuickStart.ashx) tutorial suggests, but I am wondering if there is anything specific to Azure that I need to set up.
Thanks!
I've got this working properly in my projects. I'll tell you how I did it, though this may not be the simplest or most straightforward way.
Before we get started, it's helpful to be able to check if your minified files are included in the Azure deployment package without actually deploying. It's pretty easy to do. The .cspkg file is actually a zip-formatted file, so you can open it with any zip archiver. (I like to use 7Zip for this because the right-click -> Open Archive command doesn't require you to rename the file, but you could use Windows Explorer, WinRAR, etc.) Inside the .cspkg you'll see another large file with a .cssx extension. That's a zip file too. Inside of the .cssx you'll find a sitesroot folder with a subdirectory for each website you're deploying, which will contain all your actual website files. So you can poke around in there and see what files are being deployed to Azure.
First, try editing the project file for your web project (the one that contains all the Javascript/CSS files). You can use Notepad, or in Visual Studio right-click the project, select "Unload Project", then right-click again and select "Edit ". Inside the project file, insert a section like this:
<ItemGroup>
<!-- Copy over all the minified CSS & JS to the output directory-->
<Content Include="**\*.min.css" />
<Content Include="**\*.min.js" />
</ItemGroup>
Then reload the project, repackage it, and see if your files are included in the .cspkg file. If they are, then you're done.
If not, there are a couple other things to check. Your minification might not be running at the right build stage. My minification target looks like this:
<Target Name="PrepWebApp" Condition="$(Configuration)=='Release'" AfterTargets="AfterBuild">
If that's still not working and your Web Role has multiple Sites and/or Virtual Applications in it, it's possible that the packaging steps are not running for all of the sites. So when you go to package your project for deployment to Azure, it may still not be running the minification step (along with the web.config transformations, and some other things). If that's the case, see this blog post for a way to fix it.
Just in case that blog post goes away, I'll copy the most relevant bit here. You would put this in the .ccproj file for your web role (with appropriate bits changed to match your project structure):
<PropertyGroup>
<!-- Inject the publication of "secondary" sites into the Windows Azure build/project packaging process. -->
<CoreBuildDependsOn>
CleanSecondarySites;
PublishSecondarySites;
$(CoreBuildDependsOn)
</CoreBuildDependsOn>
<!-- This is the directory within the web application project directory to which the project will be "published" for later packaging by the Azure project. -->
<SecondarySitePublishDir>azure.publish\</SecondarySitePublishDir>
</PropertyGroup>
<!-- These SecondarySite items represent the collection of sites (other than the web application associated with the role) that need special packaging. -->
<ItemGroup>
<SecondarySite Include="..\WebApplication1\WebApplication1.csproj" />
<SecondarySite Include="..\WebApplication2\WebApplication2.csproj" />
</ItemGroup>
<Target Name="CleanSecondarySites">
<RemoveDir Directories="%(SecondarySite.RootDir)%(Directory)$(SecondarySitePublishDir)" />
</Target>
<Target Name="PublishSecondarySites" Condition="'$(PackageForComputeEmulator)' == 'true'
Or '$(IsExecutingPublishTarget)' == 'true' ">
<!--
Execute the Build (and more importantly the _WPPCopyWebApplication) target to "publish" each secondary web application project.
Note the setting of the WebProjectOutputDir property; this is where the project will be published to be later picked up by CSPack.
-->
<MSBuild Projects="%(SecondarySite.Identity)" Targets="Build;_WPPCopyWebApplication" Properties="Configuration=$(Configuration);Platform=$(Platform);WebProjectOutputDir=$(SecondarySitePublishDir)" />
The build task will run in Visual Studio when you build the project. You need to make sure that the minified files are also being deployed to Azure.
I'm guessing that perhaps because the item is being generated at build-time that it's not part of the project itself, and is this ignored by the deployment step.
Please check that the deployment system being used will include all the script files and not just the ones that are in the project itself.

configure common.logging in Azure

I'm developing an app. using Common.Logging (http://netcommon.sourceforge.net/index.html).
A simplified logging configuration (which is done in web.config) is as follows:
<configuration>
...
<arg key="configType" value="FILE" />
<arg key="configFile" value="NLog.config" />
...
</configuration>
As you can see here, the configuration points another configuration file (here, NLog.config) of a backend logging framework.
My question is: when deploying in Azure, what path should I specify here (on dev, NLog.config is copied when building the solution, and placed in the bin directory). In other words, what would be the SAFEST way to get the physical place where the app is deployed in Azure?
Thanks in advance!
In code you can find the current path to the application using Server.MapPath("/"). Now, you can simply make sure that the NLog.config file gets deployed to the application folder:
Add NLog.config to your project (in the root of your web application)
Change the Build Action to Content
In order to test this you can right click on your Azure project an choose Package. In the bin\Release|Debug\app.publish folder of your Azure project you'll find a *.cspkg file. Add a .zip extension to this file and open the file with WinRAR/ZIP/7zip/... Then you'll see a file like this one: SomeWebRole_1a91f39a-49b7-4ece-873f-862172a2fa06.cssx. Here again, add the .zip extension to this file and open it.
If you navigate to the sitesroot\0 folder you'll see the files of the web application in IIS, including the NLog.config file. This way, you' can simply reference the NLog.config file in the Common.Logging settings:

Resources