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.
Related
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.
I've just made my program an exe via publish in visual studio. In that i included a usermanual.txt and a aboutus.txt file which are in bin>debug folder. After i published the program and run it. Those files are not viewing saying cannot find the file. How can i fix this
Make sure your files are included in Solution Explorer. If not, add them (Right click on project -> Add -> Existing item... then select them from disk).
This way your manuals will be part of your project.
Then, you should setup that those files are copied to same folder as your exe (bin\debug or bin\release). To to that right click on them, select Properties and notice Copy to output directory setting. It has to have "Always" or "Copy if newer" option selected.
In your code, to open file, use path like this:
string userManualPath = Path.Combine(Application.StartupPath, "usermanual.txt");
that will open file in same directory as application's .exe.
When editing your manual (adding some new text), edit the one in solution, and the changes will reflect to either debug or release or published version.
I have a website that I'm developing with ASP.NET. I'm using Visual Studio 2015. When I right-click and hit publish website the site publishes correctly except that my resources folder gets left behind. Heres what the solution explorer looks like in Visual Studio
But after I publish it here are the files that get put on Azure (accessed via FileZilla)
How do I tell Visual Studio to publish the Resources folder with the rest of the website?
Likely Answer
Open the Solution Explorer.
Right click one of the files in the Resources directory.
Choose Properties.
You now need to set two properties.
Build Action Content
Copy to Output Directory Do not copy
Do this to all the files that you would like to publish as content to the web server.
File Properties for Web Server Content
Remarks on File Properties
The Build Action property indicates what Visual Studio does with a file when a build is executed. Build Action can have one of several values:
None. Not what you want. The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file, that you do not want to publish to the web server.
Compile. Not what you want. The file is compiled into the build output. This setting is used for code files. In other words, we compile the file and the stick it into the bin directory.
Content. This is what you want. The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file. The "Content output group" is a list of files that Visual Studio will publish while also maintaining the same directory structure.
Embedded Resource. Not what you want. This file is embedded in the main project build output as a DLL or executable. It is typically used for resource files. In other words, it not only goes into the bin directory but is also embedded within a .dll or .exe file.
Copy to Output Directory. This property specifies the conditions under which the selected source file will be copied to the output directory. The output directory is normally the bin.
See Also
What are the various "Build action" settings in Visual Studio project properties and what do they do?
File Properties on MSDN
If like me you are using Visual studio 2019, just right-click on the folder and select publish "name of the folder"
Steps to add resources to be published (Visual Studio 2017):
1) Right click the resources folder and select "Include In Project"
2) Now you should see Build Action: Content on the properties for the images.
Make sure the contents of your Resources folder have the proper "Copy to Output Directory" property. Right click the files you want to copy over, select Properties, then in the Advanced section look at the value under Copy to Output Directory. Generally this is set to "Do not copy" by default since most things get packaged up in the .dll. Change it to "Copy if newer" to get it to bring over the file. It'll bring over the folder structure as well.
How to create a folder in bin/Release for Visual Studio Project?
My project calls external exe file, and I would like to place that
exe file in bin/Release/External. But every time I rebuild my project
everything is removed, so I can't just manually copy the file there.
How should I do it?
The folders inside the bin folder of your project are always deleted when you clean your solution (unless you change the project properties, but this won't solve your problem).
The simplest way of doing it is by adding the desired folder to your project and the exe file on the folder. Change the properties of the exe file to "Content" and "Copy always".
By doing that, everytime you rebuild your solution, the output will have the folder and exe file.
If the Exe file changes, you can add it as a link; ensuring you will have the latest version every time.
Or another way again..
Use Post build event where you write DOS commands.
For example in your case you can write:
mkdir $(TargetDir)\External
xcopy SOURCE_DIR_EXE $(TargetDir)\External\EXE_NAME
create a folder in the project, place the exe file in it, and set "Copy To Output Directory" property to "Copy if newer".
Just create a folder in your project, add a reference to your exe in that folder and then set the Copy to Output Directory property of the exe to Copy always / Copy if newer.
The folder structure of where the exe is will be replicated in the output directory.
Add mkdir command Post-build event command line in project options -> Build Events
You could Use a Post-build event for that.
Project Properties -> Build Events -> Post build event commandline "copy from a to b"
or second option, you create a folder "External" in your project and put your exe there. set the property "Copy to Output Direcotry" to "Copy always".
Try to integrate this into the build process:
<ItemGroup>
<_CopyItems Include="$(your_path)\*.*" />
</ItemGroup>
<Copy
SourceFiles="#(_CopyItems)"
DestinationFolder="$(BuildOutput)\External"
/>
Create a folder with your desire name in your solution, add your files there (Add Existing Item), right click on files and set BuildAction to None and CopyToOutputDIrectory to Copy Always or Copy If Newer, rebuild your project, that is it!
I have a few RDLC files in my WPF application. When I publish the project, the report files don't get published, and when I try to access them with the client I get an error saying that they're not found. I've checked the publish folder, and indeed, they're not there. I call the RDLC files with the following code:
Microsoft.Reporting.WinForms.ReportViewer rvReportViewer;
/* ... */
rvReportViewer.LocalReport.ReportPath = string.Format("Reports/{0}.rdlc", ReportName);
I've tried setting the Build Action on these to "Resource", which is what I have for my static image files, but that doesn't seem to make any difference.
Why don't the reports get copied to the publish directory? Is there a way to force this to happen, or should I be accessing them in some other way?
Thanks!
I don't know if there's special concerns with RDLC files, but here's the general approach for making sure other files get published.
Right click the file in the solution explorer, select Properties. Set the "Build Action" to "Content", and "Copy to output Directory to "Copy if newer".
Go to the project properties->Publish page. Hit "Application Files Button", check "Show all files". Set the "Publish Status" to "Include (auto)"
File Properties
Application Files
I've been using the answer by #nos for a while, but I noticed that in the publication, the set of .rdlc-files is copied to two places:
The original webapplication project relative location;
Inside the bin folder.
So if I had \Reports\Report1.rdlc, I would find in the published location:
1. <published folder>\Reports\Report1.rdlc;
2. <published folder>\bin\Reports\Report1.rdlc.
I don't mean to use copies of the rdlc's in the second location and, indeed, if I delete these, the reports are still generated.
I changed the settings for each rdlc-file to:
Build Action: Content;
Copy to Output Directory: Do not copy.
And now nothing is written to the second location.
Sorry guys this has nothing to do with "Copy Always" or "Copy if Newer". In fact I set it to "Never Copy".
This issue is resolved by changing the Build Action from "Embedded Resource" to "Content". Then when you build and publish RLDC files will get copied to the right place.
instead of using .ReportPath
**used the following code:
reportViewer1.LocalReport.ReportEmbeddedResource="[Project
Name].[FolderName if Exist].[ReportName].rdlc";
Then rebuild your deployment Project.