I'm trying to figure out a way to deploy .NET Core project containing files that are acting as data storage. I'm using .csv files. I will be modifying these files, both manually and programmatically. This project could potentially be deployed to Windows, Linux, and Mac, so I don't know where these files should be located. I've attempted to make them embedded resources and access them via scoping to the assembly, but any changes to these files don't seem to be represented when accessing this way.
How would I go about achieving what I want?
The location to store data files like that varies between systems. For the most part, you're supposed to use environment variables to store data in a subfolder of the appdata folder on Windows or a subfolder of a user's home directory on Linux. (And probably OS X too, though I don't know that one)
Alternatively, you can write a program that is "portable" or doesn't need to be installed to run, and you can store your data files in the same folder your application is run from.
Related
I'm trying to incorporate Docker into my workflow developing web apps using C#, but I stumbled across an issue trying to use it.
Long story short, I run Windows, and I have an unusual storage setup on my computer. Normally, nuget packages get downloaded into a cache in the .nuget\packages folder in the user's profile. For space reasons I had to symlink that folder to a separate hard disk, so .nuget\packages redirects to another drive.
It works well for all my regular development so far, but it seems that Docker really doesn't like the symlink. I'm guessing that maybe it doesn't rely on transparent OS access to a filesystem, and that's why it refuses to mount it, but... Is there a way to keep my Symlink, but maybe tell Docker from inside Visual Studio to use the original directory, or is there some other kind of workaround?
I'm fairly new to windows forms and I was recently tasked with creating a simple software which will be deployed by USB drives to other companies. I made this software so during first run I check for a config.xml file. If it doesn't exist, I will send the user to a form to configure their first time setup. Next time I run the program, it skips this step since the config.xml file is found with its values. The problem is when I debugged this, I found the config.xml file alongside the executable, however when I ran this on a different computer, it stored it into the appdata virtual store. I read up on this and found out it has to do with write permissions.
Is there any way I can get around this without prompting the user to do anything extra on their part such as run as administrator? I also plan on saving the resulting reports generated by the use of this program and was hoping I can have XML files which can be easily found within the application folder.
*Note, I am aware of the built-in settings system but this also stores into appdata and if the executable is moved to another directly, it loses sight of that config and wants to create another.
EDIT : Please be aware I am trying to AVOID writing to the AppData folder. The software is packaged with Visual Studio Installer - Setup Project. A msi file is created which stores the application in C:\Program Files (x86)\\. Inside this directory I have the executable, the exe.config file which is generated, and any DLLs needed. This is the folder I am trying to also store the config.xml file but due to some windows magic, the code thinks its storing it here but in reality it is being stored in the virtualStore folder located in AppData.
Have you thought of using the C:\ most computers have this unlocked. alternitively use Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
the AppData folder is stored in the username space and requires no permission. (just remember to create a folder for your program to avoid conflicts)
It is a known issue due to security concerns that write permissions are limited.
More can be learned here.
Since no one was able to answer this, I will post my solution. Instead of packaging the solution using Visual Studio Installer tools. I install the application by copying the resulting executable from the build. This version of the application has write permissions that would have not existed if the application was installed using the resulting .msi from the Installer tools.
References such as System, System.Core, System.Data, System.Web and other System like references have generally had their paths set to some system path in program files on your hard drive.
I have always thought that if you did not set copy local to true on these that they would not be copied to the bin directory or publish directory and when the application was placed on a server that it would use the system paths previously discussed to utilize these dlls on the server or whatever machine the application was running on. The reason I thought this is if you publish to a server without mvc on it the application will throw errors informing you of this issue, the same holds true for scenarios when a .net framework is missing from a server.
Is this correct? Your application will utilize the system path provided in your project on the server when running? How does copy local come into play? What happens if these files are referenced in the bin directory?
Where you reference them doesn't matter for the purposes of deployed code, that is simply to help Visual Studio know where to look.
This stackoverflow question is about where DLLs are loaded from, it is a complex topic.
In our company we have all programs in one central directory which is shared over the network. (Drive "X:")
Advantages:
configuration files are centralised
simple deploy of programs
Problem: We are using librarys (dll) for central functions. When a program which refers to one of the dll's is opened on a client, it's not possible to replace it with a newer version since the file is locked.
At the beginning it was possible to bypass the lock by renaming the file. But since Windows 7 appeared, the file can only seldom be renamed. We currently have to disconnect all clients to unlock and replace the file.
I searched for hours on the web for a solution to unlock the file. But found nothing which was working.
Do you have ideas how we could bypass/resolve this issue? We are using .NET (C#).
I am working on a Universal app, initially targeting Windows Phone 8.1.
I have an XML file that I would like to package/ship along with the app, which the app will read when it's being run and will also update it.
I've found examples of how to read and save to a local folder but nothing about how to ship data along with the app and read it.
Should the XML file be added as a resource? Or should it be stored in the local folder? If so, how do I add the file to that folder ahead of time? In a previous app I added XML files as resources, however that app was for Windows Phone 8 and the Universal apps seem to have changed how a lot of things are done so I am not sure what the best option is here.
What's the best way to do this?
Thanks!
The only way to ship data with the app is to include it in appx package by adding it to your project and marking it as content. This will place it in the app's read-only install directory.
To update the file you'll need to copy it to the application data folders. I'd probably write an access function to get the file which loads it from the local folder if it exists there. If not, then copy it over.
--Rob