I am using WIX to automatically modify web.config files depending on the environment the user is installing. I did this using WixUtilExtension and a cutom "choose environment" dialog UI.
I was wondering if there is any possible way to make WIX modify xml files inside a XAP package such as ServiceReferences.ClientConfig file?
A little bit quirky, but most probably you will end up with a custom action that will:
Extract the XAP (as a zip file)
Load the ServiceReferences.ClientConfig from a temp folder
Update the config file with the user inputs
Re-zip it as XAP
Related
Say I use some .json files to descript some object data which effect to the program's behavior, I hope to use these files in the following scenarios
The default values, for this purpose, I need a set of files follows with the application to be packed and installed.
I wish it could be edited by human manually. (Because something have no interface to be modify on UI)
Both user and the program need to kwnow the location the files will be placed after installation.
In debugging stage, I could put these files in the user\AppData\Local.. folder and I know how to access them, but I don't know how to put files into the package and will them generated to anywhere after install?
Thank you for any suggestion.
ps.
I use the "Blank App (WinUI 3 in UWP)" template to create my
application.
I'm new in UWP and WinUI, I used to write traditional Windows Form programs.
How to include externel user files into UWP side-loading package?
You could place the json file into app's project and set the file property as Content, then it will deploy into installtion folder after package install. and please note the json file is readonly in the installtion folder.
so you could call CopyAsync method copy the file to the destination folder that app's local folder with full permission.
For more details about file access permissions please refer this document.
I have a very simple .NET console application in Visual Studio. I am trying to write some words into a text file.
using (StreamWriter file = File.AppendText("log1.txt"))
{
file.WriteLine("Hello from the text file");
}
If the file does not exist, the application creates it in the autogenerated folder bin/Debug.
Is there a way to create this file in the project's directory, where I have .csproj file?
And more important, in real-world applications, when you work with files, you keep them in bin/Debug? That's why .NET creates them there firstly?
Is there a way to create this file in the project's directory, where I have .csproj file?
Yes, but this can only be done while you are working on your project. Once you are done developing it and try to publish it you won't have access to the location where you have .csproj file, because after publishing you can install it on any PC and it wont have the project you are working on.
And more important, in real-world applications, when you work with files, you keep them in bin/Debug?
No, I assume by real-world applications in your context you mean a published project '.exe' that you can run on any PC. Windows provides you three Data folders that you should use when writing your program so that it works smoothly after publishing:
User Data
Roaming User Data
All User Data
You can acess the above folders in .NET application using the Environment.SpecialFolder:
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
As per your given code, try this :
var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"log1.txt");
using (StreamWriter file = File.AppendText(fileName))
{
file.WriteLine("Hello from the text file");
}
This way you will be able to publish your program and it will still work smoothly without hard-coding the path as you were doing previously.
That's why .NET creates them there firstly?
If you don't specify a complete path, and just the file name .NET looks into the working directory of the executable, which in this case is bin/Debug
Is there a way to create this file in the project's directory, where I have .csproj file?
Yes. As explained here (second answer) you can use the post-build event to write down the value of $(ProjectDir) in a text file (using command echo $(ProjectDir) > ..\..\projectdir.txt). This macro contains the directory of your .csproj. This command will create the file projectdir.txt with your project directory after a build process so you read this file contents in your code and use what is inside it to pass to File.AppendText as the base directory to create your file log1.txt.
And more important, in real-world applications, when you work with files, you keep them in bin/Debug? That's why .NET creates them there firstly?
That depends on what you want to do. In your case the code creates the file at bin/Debug because that is where your executable are being executed. When you omit the full path to File.AppendText and just pass "log1.txt" as argument, it will create the file in the same folder as the executable are at. If you want a different folder you should specify the folder here (e.g. File.AppendText("C:/log1.txt") will create the file at C:/.
You can create the text file in the root of your project and use copy always to have them in the same place as your executable. If this is just a readonly text file then it's OK because windows doesn't allow you to modify the files reside in Programs folder in OS drive.
If you want your code to modify these text file then you need to put them in appdata folder. In real world example I did this on many project. All the database work my winforms, WPF application need goes in AppData folder.
I'm posting this here since I haven't been able to get any help from nuproj's github page.
I have some files I need to write to a specific path in my .nupkg file. After a successful build, I would like to place several files into a specific path (runtimes/win7-x64/native) instead of the default 'lib/net45' folder.
Right now, I have to open the .nupkg file (I use Nuget Package Explorer) and manually create the (runtimes/win7-x64/native) folder structure then add the appropriate files. Note - these files have to be in this specific path in order for them to work in my project.
Basically, how do I go about using nuproj to handle this for me and eliminate the need for me to do it manually? I've attached an image to better illustrate my question (the part in red is what I'm trying to automate).
You could edit the nuspec file and set the folder path for the target.
How to add a folder to a nuspec file
And then create the .nupkg file with the edited nuspec file in command line.
http://www.hanselman.com/blog/CreatingANuGetPackageIn7EasyStepsPlusUsingNuGetToIntegrateASPNETMVC3IntoExistingWebFormsApplications.aspx
And then you could add the command line to the post-build event.
I am using VSTO to build an Excel AddIn. In this project, I also added some python .py scripts to do some data manipualtion.
The whole project is a C# project, all the .py files are taken as content files of the project, in detail, what I did is setting Properities-Build Action as 'Content', setting Properities-Copy to Output Directory as 'Copy always'.
However, after publish with clickonce, when executing, I couldn't find where the content files are. I already tried like: Application.StartupPath, but did't work. I really need to find the content files path and step into them.
Thanks in advance to anyone who take time to see my question.
Publish page of an office add-in project doesn't have an Application Files button which means you can not include some files in the click once installer in the way that you do it for applications. As an option, you can put your files as embedded resources and then at startup of the add-in, extract them from resources and copy them to add-in output directory.
To do so, you can add your file to Resources.resx and then at StartUp of your add-in, extract the file from resources and save it to the deployment directory and use it.
var assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
var assemblyFolder = System.IO.Path.GetDirectoryName(assemblyLocation);
var file = System.IO.Path.Combine(assemblyFolder , "test.py");
if (!System.IO.File.Exists(file))
System.IO.File.WriteAllBytes(file, Properties.Resources.test);
Now the file is in the path specified in file variable.
Everything in Visual Studio seems to lead one to putting data files with the application.The app.config goes there, when I create an .XML data file, there is a Copy to Output property that will automatically copy that file to the exe folder. Howerver, it seems that under Vista and Win7 UAC doesn't want the application to be able to write data to any file in the application directory. So I'm changing my evil ways so that I use the LocalApplicationData folder for files I want to read and write. (I just read the app.config so I'm leaving it alone)
I'm using a VS2010 Visual Studio Installer project to create the installer for this app and I can't seem to find a way to target the folder for my .xml file to the LocalApplicationData folder. I can click on the file and see a Folder property but the dialog only has options for Application Folder, User's Desktop and User's Program Menu. Is there some way to do this in the installer or do I have to write code that checks for the file and copies it over from the .exe folder when it doesn't exist? I figure I'm late to this particular party and there must be a canonical way of handling this.
Also, I'm wondering about debugging, is there something similar to the copy if newer functionality in the build process that will now copy this .xml file automatically over to the LocalApplicationData folder whenever I update it?
The Setup project doesn't expose LocalApplicationData in the Special Folders list. You can use it anyway by doing this:
Add a Custom Folder and set the DefaultLocation property to [LocalAppDataFolder]