14

I've created a Windows C# project and made it as ClickOnce Application(Publish feature in Project properties) for Installation. I want to Include a folder which has Crystal Report (rpt) files in it. In my application I have given path of rpt file as my Installation location. How can I include this folder while publish. So that I need not copy the folder manually.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
itzArun
  • 681
  • 5
  • 11
  • 19

5 Answers5

27

So Tom has explained how to add a file. You specifically say you would like to add a folder to your ClickOnce application once you publish it. Lets assume you have a folder sitting in the root of your solution named Dependencies which contains a folder Reports which contains all of your RPT files. Here is how you would make sure your deployed app contains all of the contents of the Dependencies folder:

  1. Right click your project in Visual Studio and select "unload project".

  2. Right click and select to edit the csproj file.

  3. Before the closing </Project> tag add this:

    <ItemGroup>
    <Content Include="$(SolutionDir)Dependencies\**\*">
    <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
    <Visible>false</Visible>
    </Content>
    </ItemGroup>

  4. That will add everything from the Dependencies folder into the project. We are using the \**\* syntax at the end of the Include and %(RecursiveDir) to ensure the Reports folder will be present in the published version as well as the report files. Having set <Visible>false</Visible> you won't see the items cluttering up the solution explorer.

Community
  • 1
  • 1
Barrie
  • 1,444
  • 19
  • 26
  • 2
    You Sir just saved me a lot of wasted time. Thanks for the detailed description! – casaout Apr 15 '15 at 08:04
  • 2
    How do I copy the entire directory, not only its contentes into the Project. For example, have _the_ `foo` folder presente in the ClickOnce application folder. – Jack May 08 '18 at 19:42
23

You have to add the items to the project and mark them as 'Content' (select the item in solution explorer, right click, properties, set Build Action).

Tom Hunter
  • 5,714
  • 10
  • 51
  • 76
  • 2
    This won't create the needed folder though. The files are included in the program directory, but if you need the folder created how would you do that? – Patratacus Jan 22 '14 at 16:38
  • 1
    @Patratacus: The files must be added under the folders where they should be placed after installation. This will create the folders. One more thing left: make sure you change the publish status column to the added files in the Application Files dialog to Include, as opposed to Include (Auto). See [this](http://devrecipeshb.blogspot.co.il/2018/02/adding-files-and-folders-to-click-once.html). – Veverke Feb 04 '18 at 08:54
2

Let's say that we have two projects: main - ProjectA and some other ProjectB referencing ProjectA. In ProjectB we have a folder FolderB with some files that should be included when publishing (pdf, rpt, etc.) ProjectA.

Once we build ProjectA there will be all referenced files and folders in the bin directory. But when we publish the solution using the ClickOnce tool, the folders from the referenced ProjectB won't be included in the installer and you won't see them in the Application Files window in the project publish settings.

The solution for this issue is to create a new folder called FolderB in ProjectA and add the existing items from FolderB in ProjectB to this new folder in ProjectA using the Add As Link option. Then all the files, including the files linked from the ProjectB folders, will be included when publishing of ProjectA.

FIL
  • 1,148
  • 3
  • 15
  • 27
0

It's been a long time since the OP, but when I add a folder to my solution, add a Crystal Report to that folder and mark it as "Content" (per Tom), then Publish and install - the folder and report gets added to the ClickOnce installation location. So Tom's solution worked for me.

CP.
  • 47
  • 5
0

Barrie has the best solution, really solves all I needed! No need to include same files in multiple projects, just setup pre-build event that copies files in debug for local functionality and debugging. Solves my problem with rdlc (reports) having in one location and using them in multiple projects.

Hrvoje Batrnek
  • 535
  • 1
  • 5
  • 15