[英]How to publish my C# project using OpenCV Nuget packages in Visual Studio?
I have developed an opencv application using windows form and C#. 我使用Windows窗体和C#开发了一个opencv应用程序。
The opencv packages I got from the Nuget packages manager (EMGU.CV and ZedGraph). 我从Nuget包管理器(EMGU.CV和ZedGraph)获得的opencv包。
Everything works fine in visual studio, but when I publish the project and install the program in my machine, it throws an exception when I click a button that performs some opencv operations. 在visual studio中一切正常,但是当我发布项目并在我的机器上安装程序时,当我单击执行某些opencv操作的按钮时会抛出异常。
I guess the opencv packages didn't come along with the final published project, so how do I do to make it export when publishing, I thought it would be an automated process, I have already used other nuget packages and I had no problem with it. 我想opencv软件包没有附带最终发布的项目,所以如何在发布时将其导出,我认为这将是一个自动化过程,我已经使用了其他nuget软件包,我没有遇到任何问题它。
What Am I missing here? 我在这里失踪了什么?
After some days waiting for an answer, and looking for solutions, I've figured it out how to solve this issue. 经过几天等待答案,并寻找解决方案,我已经弄清楚如何解决这个问题。
I came across this question: The type initializer for 'Emgu.CV.CvInvoke' threw an exception 我遇到了这个问题: 'Emgu.CV.CvInvoke'的类型初始化程序引发了异常
Which led me to this: http://www.emgu.com/wiki/index.php/Download_And_Installation#The_type_initializer_for_.27Emgu.CV.CvInvoke.27_threw_an_exception . 这让我想到了这个: http : //www.emgu.com/wiki/index.php/Download_And_Installation#The_type_initializer_for_.27Emgu.CV.CvInvoke.27_threw_an_exception 。
More precisely this part: 更确切地说,这部分:
First of all, I don't know why the compilation runs fine inside visual studio enviroment and why not when publishing the project as it is. 首先,我不知道为什么编辑在视觉工作室环境中运行良好,为什么不在发布项目时。 For some reason, the Nuget packges are not enough for publishing the project, you need to add the .dll files manually yourself (not sure why this occurs once I have worked with Nuget packages before and this workaround was not necessary). 出于某种原因,Nuget包装不足以发布项目,您需要自己手动添加.dll文件(不知道为什么在我之前使用过Nuget包之后会发生这种情况,并且不需要这种解决方法)。
To find the .dll files you go to your project directory, then you go to bin\\Debug\\x64 or bin\\Debug\\x86 (depends on which operating system you are targetting - 32 bits or 64 bits -in my case I added all .dll files from x86 folder, I guess you can add from both folders if in doubt). 要查找.dll文件,转到项目目录,然后转到bin \\ Debug \\ x64或bin \\ Debug \\ x86(取决于您要定位的操作系统 - 32位或64位 - 在我的情况下,我添加了所有来自x86文件夹的.dll文件,我想如果有疑问你可以从两个文件夹中添加)。
The Debug folder of your project is build every time you run the project inside Visual Studio enviroment, so if your Debug folder is empty then you just need to run the project one time to be able to find the auto generated files inside that folder. 每次在Visual Studio环境中运行项目时,都会构建项目的Debug文件夹,因此如果您的Debug文件夹为空,那么您只需运行一次项目就可以找到该文件夹中的自动生成的文件。 Just a side note here, you can use either the Debug or the Release folder inside bin, just remember to check if you compiled the project in Debug mode for Debug folder, or Release mode for Release folder, otherwise the desired folder will be empty, as explained before, I found no differences between the files generated, I added the dll files from Debug\\x86. 这里只需注意,您可以使用bin中的Debug或Release文件夹,只需记住检查是否在Debug文件中为Debug文件夹编译项目,或者Release文件是Release文件夹,否则所需的文件夹将为空,如前所述,我发现生成的文件之间没有差异,我从Debug \\ x86添加了dll文件。
Once you have located the .dll files, you go to Visual Studio, right click on the project in the Solution Explorer tab, then Add ---> Existing Item. 找到.dll文件后,进入Visual Studio,在Solution Explorer选项卡中右键单击该项目,然后单击Add ---> Existing Item。
Go to the folder where the .dll files are, select all and click Add. 转到.dll文件所在的文件夹,选择all并单击Add。
Once you have done this, the .dll file will be shown in the Solution Explorer. 完成此操作后,.dll文件将显示在解决方案资源管理器中。
Right click on each .dll file added in the Solution Explorer, and open the properties tab by clicking Properties. 右键单击解决方案资源管理器中添加的每个.dll文件,然后单击“属性”打开“属性”选项卡。 On the Properties tab, go to option Copy to Directory and change the field to Copy Always (the emgu documentation link provided above states to use the option "Copy if newer", but to make sure I chose "Copy always", it worked fine for me). 在“属性”选项卡上,转到“复制到目录”选项,然后将该字段更改为“始终复制”(上面提供的emgu文档链接指示使用“如果更新则复制”选项,但为了确保选择“始终复制”,它工作正常为了我)。 Repeat the process for all .dll files added. 对添加的所有.dll文件重复此过程。
Now you are ready to go for publishing the project as it is,just remember doing this every time before publishing your project to see if no .dll files are missing, so once you got to final version of your program, run it, and then make sure to check the .dll files, it might have new ones to add or to remove. 现在您已准备好按原样发布项目,只记得在发布项目之前每次都这样做,看看是否缺少.dll文件,所以一旦你到达程序的最终版本,运行它,然后确保检查.dll文件,它可能有新的要添加或删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.