简体   繁体   English

在发布版本中找不到 wpf 字符串文件,但在调试 c# 中工作

[英]wpf string files not found on release version but work in debug c#

I have finished a very basic application (wpf/c#).我已经完成了一个非常基本的应用程序 (wpf/c#)。 The solution is made of 3 projects:该解决方案由 3 个项目组成:

  1. The main project for the app应用程序的主要项目
  2. The Class Library Project to store app resources (images and txt files)用于存储应用程序资源(图像和 txt 文件)的类库项目
  3. The Setup project which I use to create exe file for distribution to other machines.我用来创建 exe 文件以分发到其他机器的安装项目。

While the project works fine in debug mode when I deploy it using the Setup project and install on the computer I can access the image files from the Library Project (I can see there is a dll file for the library project in the application folder) but it fails to access the text files, complaining the path was not found.虽然当我使用 Setup 项目部署它并安装在计算机上时,该项目在调试模式下运行良好,但我可以从 Library Project 访问图像文件(我可以看到应用程序文件夹中有一个用于库项目的 dll 文件)但是它无法访问文本文件,抱怨找不到路径。 This is my very first time I completed the application and attempted to deploy it so am a bit at a loss why the setup does not provide correct references to the text files and yet it seems to work fine with image files which are located in the same library project.这是我第一次完成应用程序并尝试部署它,所以我有点不知所措,为什么设置没有提供对文本文件的正确引用,但它似乎可以很好地处理位于相同位置的图像文件图书馆项目。 Can someone point me in the right direction where to look at it to troubleshoot?有人可以指出我正确的方向在哪里查看它以进行故障排除吗?

I have cleaned and rebuilt all projects in the solution.我已经清理并重建了解决方案中的所有项目。 retested in debug mode (works fine).在调试模式下重新测试(工作正常)。 tried to search msdn and StackOverflow but I cannot find any guidance I could use or follow.试图搜索 msdn 和 StackOverflow,但我找不到任何可以使用或遵循的指南。

I would like to be able to display text from the text files in the released/installed application version the same way it works in debug mode.我希望能够在已发布/已安装的应用程序版本中显示文本文件中的文本,就像它在调试模式下的工作方式一样。 At the moment it fails to find the relevant txt files.目前它无法找到相关的txt文件。

Finally, I have managed to crack it.最后,我设法破解了它。 Posting the answer for anyone having the same problem.为有同样问题的任何人发布答案。 The issue here was not with the file path, even though I came up with a more clearer technique of building it, see my comments above.这里的问题不在于文件路径,即使我想出了更清晰的构建它的技术,请参阅我上面的评论。 The problem was with the way Setup Project in VS2017 was creating a package.问题在于 VS2017 中的安装项目创建包的方式。 It is handling differently images and text files, even though both are in the same Library Project, essentially for text files I had to do the following to get it working:它处理不同的图像和文本文件,即使它们都在同一个库项目中,基本上对于文本文件,我必须执行以下操作才能使其正常工作:

Open File System in Setup Project在安装项目中打开文件系统

Create the 'Resources' Folder under 'Application Folder'在“应用程序文件夹”下创建“资源”文件夹

Set the 'Resource' folder 'AlwaysCopy' property to 'true'将“Resource”文件夹的“AlwaysCopy”属性设置为“true”

In 'Resources' folder right-click and select Add> File...在“资源”文件夹中右键单击并选择添加>文件...

Navigate to the folder with the files and select them all (make sure the files are setup as Resources or embedded resources)导航到包含文件的文件夹并全选它们(确保文件设置为资源或嵌入资源)

Rebuild the Setup Project重建安装项目

. .

So summarising I had to specifically tell Visual Studio to build the folder structure in the Application Folder during the install.所以总结一下,我必须特别告诉 Visual Studio 在安装过程中在应用程序文件夹中构建文件夹结构。 Now when I run the installer the text files are included in the package and created during standalone installation.现在,当我运行安装程序时,文本文件包含在包中并在独立安装期间创建。 Also included a screenshot below.还包括下面的屏幕截图。

设置项目文件系统

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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