简体   繁体   中英

Include a Folder in ClickOnce Application

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.

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.

您必须将项目添加到项目并将其标记为“内容”(在解决方案资源管理器中选择项目,右键单击,属性,设置构建操作)。

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

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

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM