Add "already added" folders to solution? - azure

I created a couple of App_LocalResource folders along with alot of resx files in my MVC4 solution. But when web-deploying to Azure, they aren't recoqnized/found/listed in change sets. None of the folders are pushed to Azure. I can't add them to the solution cause they are already there? I created the folders through VS so i suppose they are included in the solution on creation.
What do I do?

You need to set each of the .resx files' "Copy to Output Directory" property to "Copy if newer" or "Copy always." If you don't change this property for any of the .resx files in an App_LocalResources folder, the entire folder won't show up in your resulting cloud service package, and it won't appear in the Project/csx/Debug/roles/rolename/approot/bin folder when you debug locally either. When you deploy the package without changing each .resx file's "Copy to Output Directory" property, they won't be included in your service package when its uploaded via web deploy.
Also, from a maintainability standpoint, I would recommend looking into using Azure Tables instead of .resx files. They're more flexible in a deployed environment because a Table entity can be changed at runtime if necessary, without redeploying.

I changed Build Action for the resx file to Content instead of Embeded Resource. Embeded Resource complies the resources into a dll where you cant access the usual way.

Related

ASP.NET Core, Could not find file. How Can I publish it?

I have found many questions like this, but I'm still having problems to get a "static" file.
The task should be simple. Just get a cshtml file content. A file that it's already in the project. But it's taking forever to figure it out.
This is the error that I'm getting (only when in production)
Could not find file 'D:\home\site\wwwroot\AppData\template.cshtml'.
Looking into the 'D:\home\site\wwwroot' folder, indeed the 'AppData' doesn't exist. But then how can I publish the AppData and its files?
This is how I'm getting the file
string contentRootPath = webHostEnvironment.ContentRootPath;
return $"{contentRootPath}/AppData/{filename}";
This is inside .csproj
<Folder Include="AppData\" />
To publish the project I'm using DevOps Azure. Is there any configuration that I'm missing?
I don't know if this is the right approach, but it's working (for now).
In DevOps/Pipelines/MyMypeline/Tasks, I add Copy files Task.
Source Folder: MyProject/AppData
Target Folder: $(Agent.TempDirectory)\WebAppContent\AppData
The next task (Archive files) it was already set. So in resume, the pipeline will get the files from AppData and add in the same place where the solution was build. And the other task will zip all. Than another task (Azure Web App) will sent the zip to my AppService.
I still have to test when do the swipe from dev to prod, but for now that's it.

Publish website to Azure, remove additional files at destination, but ignore specific folders

I currently manually delete obsolete folders from a published azure website. I know there is an option in visual studio to Remove additional files at destination. My problem is that I have an Images folder (quite large) that users upload, that will be deleted when I publish with this option checked. My question is, is there a way to use this option with exclusions? Meaning, to delete all files that are not in the local project except "\Images" folder?
You can most likely customize the web deploy usage from VS to do what you want but I don't think I would recommend it since things like that tend to get fragile.
I would suggest changing your architecture to store the images in a blob container, then possibly mapping your blobs to a custom domain (https://azure.microsoft.com/en-us/documentation/articles/storage-custom-domain-name/).
Having your images in blob storage will also prevent any accidental deletion of the Images folder by someone else that doesn't know it shouldn't be touched (or you simply forgetting about it one day).
Using blob storage will also allow you to configure CDN usage if ever find that you needed it.
Another option would be to create a virtual directory on your WebApp configuration and put the Images there - that way your VS deploy/publish wouldn't be modifying that subdirectory. This link may help with that: https://blogs.msdn.microsoft.com/tomholl/2014/09/21/deploying-multiple-virtual-directories-to-a-single-azure-website/

Azure project - which subfolders/files should be checked into version control?

I am working on a small Azure project (using Visual Studio 2015). I have created a Azure Cloud service project with only one webjob. Inside the cloud service project, vs2015 created some subfolders like 'csx', 'ecf', 'XXXXXXXXContent', 'Profile', 'rcf'.
I wonder whether I should checkin these subfolders and the files inside. Of course, the 'Release' and 'Debug' folder inside these subfolders won't be checked in.
Folders with lowercases are generated during compilation and publish process.
csx: Packaged files which ready to be published. But as of Azure Tools v1.4, it is no longer generated unless you run in emulator. This blog post describes in detail.
rcf: which stands for Role Content Files. You already has ---WorkerRoleContent and rcf is generated through build configuration. You can think it as a kind of bin folder for contents.
ecf: It is generated folder for diagnostics settings depended on `diagnostics.wadcfgx' file. The file is specific for publish settings, so you should not include it in source control.
Overall, all three folders are automatically generated for publishing and they should not be added to source control.
However, Profile and ----Content folders are required to maintain your publish settings.

Include referenced assembly's configuration in cspkg

I have an executable that I want to be deployed together with my Azure web role. The executable has a configuration file that needs to be included as well.
I tried adding a reference to the executable's project in my web role project, which made the exe file appear in the bin folder of the cspkg, but not the configuration file.
How can I get the configuration file to be included as well?
It seems wrong to include it directly as a content file in the web role project because this file is a build artifact (app.config gets renamed to .config.exe during build).
Thanks!
In an early SDK they added the concept of Role Content folders, or folders you could point to in the service definition file and say anything in this folder, add it to the package and deploy it with the role. If you look at the schema for the Service Definition you'll see these listed on the both the web and worker roles schemas. You can manually add this and point to any location on the local system and anything in that directory will be picked up and included.
<WebRole name="SimpleWeb" vmsize="Small">
...
<Contents>
<Content destination="ConsoleApp">
<SourceDirectory path="c:\src\SimpleWebContent\ConsoleApp\BuildOutput" />
</Content>
</Contents>
</WebRole>
For example, you could point to the output directory of the build for your executable so that anything that is generated by your build for that executable would be included. You can set the destination directory in relation to the app root, but the tricky part is the source directory. Note in my example above the full path is provided. The documentation says that you can use a relative path, but I tried many combinations and the behavior seemed very quirky. The complete path does work.
The VS SDK tools didn't expose this until SDK 1.7 and it's still not very good. Phil Hoff did a blog post on it called "Add Files to your Windows Azure Package using Role Content Folders". Note that when you use this method of adding the files you won't see the content elements appear in your service definition. They get auto injected at package time. If you are doing this as part of a build process that may not happen since VS tooling is doing the injection, but to be fair I didn't try calling cspack directly to see if having the content elements included in the service definition file actually packaged those or not. Also, I found that just adding a new folder and just having files under that folder didn't seem to work. I had to actually add the files by name there, which seemed wrong. I did hack the .ccproj file to use a wildcard on the folder include, which did work, but also seemed like a hack to me.

access certain folder in azure cloud service

In my code (which has worker role) I need to specify a path to a directory (third party library requires it). Locally I've included folder into project and just give full path to it. However after deployment of course I need a new path. How do I confirm that whole folder has been deployed and how do I determine a new path to it?
Edit:
I added folder to the role node in visual studio and accessed it like this: Path.Combine(Environment.GetEnvironmentVariable("RoleRoot"), "my_folder");
Will this directory be used for reading and writing? If yes, you should use a LocalStorage resource. https://azure.microsoft.com/en-us/documentation/articles/cloud-services-configure-local-storage-resources/ shows how to use this.
If the directory is only for reading (ie. you have binaries or config files there), then you can use the %RoleRoot% environment variable to identify the path where your package was deployed to, then just append whatever folder you refernced in your project (ie. %RoleRoot%\Myfiles).
I'd take a slightly different approach. Place the 3rd party package into Windows Azure blob storage, then during role startup, you can download/extract it and place the files into the available Local storage (giving it whatever permissions the app needs). Then leverage that location from your application via the same local storage configuration entry.
This should help you reduce the size of your deployment package as well as give you the ability to update the 3rd party components without completely redeploying your solution. And by leveraging it on startup, you can guarantee that the files will be there in case the role instance gets torn down and rebuilt.

Resources