Include Folder From Other Project While Click-once Publish - c#

I have 3 projects in my solution MainProject, Library, and Configuration. In the Configuration project I have a folder named Conf that contains XML configuration files when I publish the main project the Conf folder and its content is excluded.
How can I include the folder and the contained files while publishing?

You need to specify that they are content and should be included. By default, things like XML files are set to a "Build Action" of "None".
In the Solution Explorer window, right-click each file to get the Properties view. Then choose "Build Action" as "Content" and "Copy to Output Directory" to "Copy if newer". When you build and/or publish, you'll see those files get the appropriate *.deploy extension in the output.

Related

How can I fetch a file to be read in StreamReader and listed in a ListBox? [duplicate]

Task is to form Visual Studio 2010 project so, that during any build or publish some foo.exe utility should be copied to output (bin) directory.
Early I have made PostBuildEvent task in .csproj (MSBuild-file):
<PropertyGroup>
<PostBuildEvent>
Copy "$(SolutionDir)Tools\foo.exe" "$(ProjectDir)$(OutDir)foo.exe"
</PostBuildEvent>
</PropertyGroup>
But this is not universal. During publishing (Visual Studio 2010) foo.exe appears in bin directory, but is not copied to output publish directory. Maybe I do everything completely wrong and there is standard mechanism to include files in projects to be later, during build or publish, copied to bin?
There is and it is not dependent on post build events.
Add the file to your project, then in the file properties select under "Copy to Output Directory" either "Copy Always" or "Copy if Newer".
See MSDN.
I only have the need to push files during a build, so I just added a Post-build Event Command Line entry like this:
Copy /Y "$(SolutionDir)Third Party\SomeLibrary\*" "$(TargetDir)"
You can set this by right-clicking your Project in the Solution Explorer, then Properties > Build Events
In Solution Explorer, please select files you want to copied to output directory and assign two properties:
- Build action = Content
- Copy to Output Directory = Copy Always
This will do the trick.
Add the file to your project.
Go to the Properties of that file.
Set "Build Action" to Embedded Resource.
Set "Copy to Output Directory" to Copy Always.
There is another way that can copy items that are "outside" the Solution (which also makes it technically possible to copy Solution Items as well).
In Solution Explorer, right-click in your project and choose "Add... Existing Item". Locate the file in question (it can by any type, not just code), and next to the "Add" button, click the drop-down arrow and select "Add As Link".
In Solution Explorer, select the item that was just added to your project and change the Copy to Output Directory property to Copy if newer or Copy always, as appropriate.
In my case, setting Copy to Output Directory to Copy Always and Build did not do the trick, while Rebuild did.
Hope this helps someone!
Try adding a reference to the missing dll's from your service/web project directly. Adding the references to a different project didn't work for me.
I only had to do this when publishing my web app because it wasn't copying all the required dll's.
Just so my fellow neuronically impaired comrades might chance upon it here, I had assumed that, for web projects, if the linked file was an external .config file that the "output directory" would be the same directory that web.config lives in, i.e. your web project's root. In retrospect, it is entirely unsurprising that it copies the linked file into the root/bin folder.
So, if it's an appSettings include file, your web.config's open tag would be
<appSettings file=".\bin\includedAppSettingsFile.config">
Duh.

VS solution folder not generating in the bin/debug or release folder

I have added a solution folder on my visual solution project.
I have added some text files inside that folder.
I have Built and Rebuilt my solution but still nothing.
The error I get when trying to access a file from the folder:
System.IO.StreamReader file0 = new System.IO.StreamReader(Path.Combine(Environment.CurrentDirectory, #"newFolder\SampleText.txt"));
An unhandled exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
Additional information: Could not find a part of the path 'I:\Programming\Projects\SampleProject\SampleProject\SampleProject\bin\Release\newFolder\SampleText.txt'.
The path to the Release folder is valid, but newFolder is not inside.
I don't understand why it is not being generated, any help would be great.
Click on your text file, change Copy to Output Directory to Copy if newer or Copy always. This will copy the file and any folder structure beneath it up to the project level and re-create it in the output folder.
The answers correct. You need to change "Copy to Output Directory" to "Copy Always" or "Copy If Newer" BUT YOU NEED TO DO ONE MORE THING. You need to choose Build Action as "Content". By doing so the folders that contain the files are generated in debug folder automatically without hassle. The other Build Actions may also work I am not sure but not "Resource" one.
If you set text file's property "Copy to Output Directory" to "Always" in solution then folder that contains this file will be created automatically
If you create your folder at the project level as opposed to the solution level, you can then go to each file in that folder and view the Properties (right-click / Properties). Here, can then set the "Copy to Output Directory" option to "Copy Always" or "Copy if newer", whichever one is appropriate for your purposes.

Deploy external file in c# solution with clickonce

I've a problem with Visual Studio Express 2010 c# edition.
I've a project that reference a DLL. This DLL has an external Excel file marked as
Build Action = Content
Copy to Output Directory = Copy Always
When I build the solution, this Excel file is correctly copied into BIN\release solution folder.
BUT if I try to deploy the same solution, with Publish wizard, the Excel file is not copied in the install directory.
Please, could anyone help me?
Open the Publish properties for your ClickOnce project. Then click on the 'Application Files ...' button. That launches a dialog where you can control which files are being included in the publishing package.
In order for your XLSX file (or any other non build file) to appear in that dialog you need to mark is as 'Content' in the Build Action of the properties window.
Are you saying that the Excel file is referenced only by the dll you are including in your project? That is a secondary reference, and ClickOnce will not see it and automatically include the file.
First, on your dll, I'm assuming it is referenced directly by your project. If so, then be sure you have added it to your project and set the Build Action to "none" and "copy to output directory" to "do not copy". Then delete your reference to it and re-add it, pointing it to the version now included in your project. Set the "copy local" property to "true". This will ensure the dll itself gets deployed correctly.
For the Excel file, you are going to have to add it to your project. Set the build action to "content" and set "copy to output directory" as "copy always". It will not be included automatically because it is a secondary reference to the ClickOnce app, not a direct/primary reference like the dll is.
Try to include this file into solution and set "Copy to Output Directory" to "Copy always"
It appears your file is not listed in the "PublishFiles" list. Open the Projects Properties, go to "Publish" Tab, click on "Application Files" button, make sure you see the DLL file in the list of files with Publish Status as "Include".
You could avoid the problem by inserting the Excel file as a resource, then writing it out like this:
File.WriteAllBytes(DestinationFileName, Properties.Resources.MyResourceFile);
I'm making an assumption that the Excel file is some kind of template you are using to build an output file from.

c# deployment: install additional file in the installation directory

how to install additional file such as some excel or webpage shortcut in the installation directory so that my executable should be able to access that file? please help
Add the file to your project.
Set the build action to "content".
Set "copy to output directory" to "copy always".
The file should be included in the same folder as the rest of your deployment. You should be able to see it by building it and looking in the \bin\release or the \bin\debug folder.
If it's not there, click on the Application Files button and see if it shows up there.
In the solution explorer, right click on the file and go to properties. Set "Copy to output directory" to "Copy if newer". You may also need to set "Build action" to "Embedded resource" if it is not already.

WPF C# XML resources in subfolder not getting built

Currently in my project directory I have a folder called "Data" and in it I have two XML files that I use in my WPF application. I have set the XML files as "Resource" and the "Copy to Output Directory" option to "Copy Always". However, the following code throws a DirectoryNotFoundException because the files aren't being copied over to bin\debug when I build my application.
return new Game(XDocument.Load("Data/Game.xml").Root);
How do I make it so that everytime I build the files are moved over without having to do it manually everytime I change my XML?
Set 'Build Action' to None
When you set Build Action to Resource - it means, that VS will automatically pack this file into assembly as embedded resource. More about Resource Files on MSDN
And when 'Build Action' is None - Studio has nothing else to do, but to follow "Copy to Output Directory" command.

Categories