Visual Studio Setup Project - one file in two locations - c#

What I want is make my setup project install same file in two different locations. When I try to do that, it adds that file again into my project which doubles the size of the .msi in the end. What can I do about this? Thanks !

When adding a file:
Go to add Existing Item
In the bottom left corner where it says Open drop the drop down box and select Link file
click ok
This will then add the file as a link instead of copying the file to your project directory
More info here

What you could do is to install the file at one place. Create a Custom Action that creates a copy of the file on the second place. Please take care that you remove that file as well at uninstall time.

Related

How to create a .tfignore file?

Visual Studio 2017 (v15.9.9).
I can't seem to figure out how to create a .tfignore file. If I do it manually, windows tells me I need to add a file name. And I am not seeing anywhere via the IDE to create one.
I'm used to GIT, where I can right click on a pending check-in file (that has changed) and just select "Ignore". But I don't seem to have that option, despite the fact that all the results I find via Google tell me that I should.
You can create your file as .tfignore.. The last dot will be removed automatically.
This can be solved using the same steps as How to create .gitignore file (just replace .gitignore with .tfignore):
Create the text file tfignore.txt
Open it in a text editor and add your rules, then save and close
Hold SHIFT, right click the folder you're in, then select Open command window here
Then rename the file in the command line, with ren tfignore.txt .tfignore
However, an easier/quicker way to get around this Windows Explorer error is by appending a dot to the filename without extension: .tfignore. will be automatically changed to .tfignore
the easiest way is to open command prompt and navigate to your project folder. Then
notepad .tfignore
after that just save file and you are good to go.
Or you can also use
echo "" > .tfignore
Note that you may need to manually include this file to TFS

How can I publish a Windows Form app to include a csv file?

I'm creating a Windows Form application that is going to be used as a sign in system at my college. I was given a .csv file that includes student id numbers, names, teachers, and current courses. I have the app created and it works when I use it on my computer. However, when I publish the application and install it on a different computer, the streamReader that I use to access the .csv file is not able to use the .csv file because it's nowhere in the published application. I have tried adding the file to the root directory of the project, but I can't find out how to access it from there. I've read a few forums that talk about adding the file as a "resource," but I don't know enough about that to make it work for what I'm doing. Any assistance would be appreciated. Thanks!
In visual studio, add the file to your project (Add Existing after right click on the project). You'll need to add a build action as well, to tell the IDE to copy the file to the output directory. To do that, right click on the file you added, go to Properties, and look for BuildAction.

Storing text files in Visual Studio

Right now I am reading in text files in my C# code in Visual Studio. The text files are saved onto my computer and whenever we want to run the code on another computer, we have to change the path for the text file within the code so it will work. My question is, is there any place you can save the text files within the project so that you do not have to change the path everytime to run it on different computers?
Add the txt files to the project. Manage them in your source control just like any other file.
You can add any kind of file you like. They just sit there doing nothing ( it doesn't try to compile them or anything), you can group them into folders for better clarity.
You can add a folder to your project to hold the various text files:
Right mouse click on your project
Select Add New Folder
You can place any type of file into this folder.
Hope this helps.

Link to config file in .Net setup project

I am creating an installer for my C# application, and I want to put a link to the configuration file into the start menu, so that users can open it for editing in notepad from the program folder in the start menu.
I seem not to be able to put a link to it however - does anyone know how to do this? (Really, I would just love to put "[targetdir]\myapp.exe.config but VS doesn't let me edit the field, only select from a file browser).
Many thanks,
Rob
I found the solution and it's pretty easy:
Add Project Output for your project in the setup project
Select Project Output from File System in left pane and go to the properties of the project output. Then add a filter *.config to remove the .config file from your project output.
Rename the app.config from your actual project to the output name that your App exe ([ProductName]) will have along with the config extension ofcourse.
Add the [ProductName].config to your setup project as a File.
Create a Shortcut to that file and add it in any setup folder desktop or program folder.
Voila.
You're all set.
Isn't the config file added in your installer? You should be able to select it when prompted for the shortcut target (the "Select Item in Project" dialog). Please note that in this prompt dialog you first need to browse to the folder which contains it (for example double-click "Application Folder").
If the config file is not added, you need to manually add it in "Application Folder". Only then you can create a shortcut to it.
Please note that Visual Studio doesn't support shortcuts to a specific file from a project output which generates multiple files. In this case you can try using a custom action which creates the shortcut through custom code.
I remember doing it in Vs2005 using as below:
File System Editor > Users Programs Menu
Add> Folder
Add file (Say Config file) point it to the its location

Post build copy config file to another project

I have a solution which contains a website and various class libraries. The exists on the file system like so:
C:\Projects \MyWebsite\dev\MyWebsite.sln
C:\Projects\Core\MyClassLibrary1.csproj
C:\Projects\Core\MyClassLibrary2.csproj
I want to move the App.config file from MyClassLibrary1 project to the bin of the MyClassLibrary2. I want to do this on post build in VS or MSBuild using relative paths if possible. This way anybody checking out the projects will not have to modify any paths if they choose to locate the project in a different location.
I have already tried the following approaches but to no avail.
copy /Y "$(ProjectDir)App.config"
$(ProjectDir)\..\ MyClassLibrary2\$(OutDir)\ MyClassLibrary2.dll.config"
Any ideas?
Thanks
Consider adding the App.config file in your second class library using Visual Studio Add As Link.
Add -> Existing Item -> Add As Link
The Add As Link command is shown if you click the dropdown next to regular Add button in Visual Studio. This way you can reuse the file in multiple projects.
Try some other common MSBuild properties, although João has a better suggestion I think.

Categories