问题
I have a read-only data file (for IP geolocation) that my web role needs to read. It is currently in the App_Data folder, which is not included in the deployment package for the cloud service. Unlike "web deploy", there is no checkbox for an azure cloud service deployment to include/exclude App_Data.
Is there a reasonable way to get the deployment package to include the App_Data folder/files? Or is using Azure storage for this sort of thing the better way to go? (cost and performance wise)
Am using Visual Studio 2013 and the Azure SDK 2.2
UPDATE: - Found that the App_Data files are actually deployed under /bin/App_Data! So they are there. - Actually ended up moving the file to a storage blob, and copying it to a local storage area on the azure server in the app on startup. This greatly reduced the size of the deployment package, since the static file is not being carried in the package.
回答1:
If App_Data is not empty, it will be published on Azure website and you can access it via
var folder = Server.MapPath("~/App_Data/");
You can also create folders and write files there
var folder = Server.MapPath("~/somefolder/");
Directory.CreateDirectory(folder);
var path = folder + "file.txt";
File.AppendAllText(path, "some text");
回答2:
I experienced the same issue.
after deploying my service, I run a recursive directory search on the local directory on the Azure server (string appRoot = Environment.CurrentDirectory;) and found that the stored files are under E:\\approot\\App_Data\\<file name> then I used the following code appRoot = Path.Combine(appRoot + @"\", @"App_Data\<file name>t");
回答3:
Maybe take advantage of Blob storage instead to upload the file, manage it, etc. This link here documents also how to programmatically access it.
http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/
来源:https://stackoverflow.com/questions/19899847/how-to-deploy-app-data-files-with-azure-cloud-service-web-role