简体   繁体   English

在Visual Studio中对具有不同目标平台的另一个项目的项目引用

[英]Project reference to another project with different target platform in Visual Studio

I am developing Azure Function in visual studio, it running well locally. 我正在Visual Studio中开发Azure Function,它在本地运行良好。 When I try to publish to AZ, it gives me failed error: Please change project B target platform to x64 via build configuration manager. 当我尝试发布到AZ时,它给了我失败的错误:请通过构建配置管理器将项目B目标平台更改为x64。

But I already did so, otherwise it can not running, even locally. 但是我已经这样做了,否则它甚至不能在本地运行。 However, I did not change the target platform to x64 in the dialog after I right click the project B's properties. 但是,右键单击项目B的属性后,没有在对话框中将目标平台更改为x64。

Problem is after I make the change there, it did not working even locally. 问题是我在此处进行更改后,即使在本地也无法使用。 Project A with target platform AnyCPU which reference to peoject B gives me another error: Project A: Could not load file or assembly, Project B. 具有目标平台AnyProject的项目A引用了对象B的另一个CPU给了我另一个错误:项目A:无法加载文件或程序集,项目B。

Any idea on how this whole thing should work both locally and on Azure. 关于整个事情如何在本地和Azure上运行的任何想法。 Am I in the wrong place at beginning? 一开始我在错误的地方吗?

They all in same solution, the executing project call Porject A, and project A call project B 它们都在同一解决方案中,正在执行的项目调用Porject A,而项目A调用项目B

Thanks! 谢谢!

I find that Platform target in Property pages (aka right click on Project, Properties> Build ) controls the platform indeed. 我在“属性”页面(也可以在“项目” Properties> Build上单击鼠标右键)发现“ Platform target确实控制了平台。 Leave it as Any CPU and change Configuration manager to x64, projects are built as x86, ie the preference of Any CPU . 将其保留为Any CPU并将Configuration manager更改为x64,将项目构建为x86,即Any CPU的首选项。 I also find in a brand new project, modify Configuration manager to x64, Platform target is changed to x64 automatically and projects are built into x64 bits. 我还在一个全新的项目中找到了,将Configuration manager修改为x64, Platform target自动更改为x64,并且将项目内置到x64位中。

So I guess running well locally happened because your projects actually targeted at x86 before. 因此,我猜想本地运行良好是因为以前您的项目实际上是针对x86的。 After Platform target changed, x64 doesn't work well due to the inconsistency of projects platform. 更改Platform target后,由于项目平台的不一致,x64无法正常工作。

Based on this, I would suggest as @Jeremy said, make sure all project Platforms are set to Any CPU , we could delete x64 platform settings directly for a clean configuration. 基于此,我建议就像@Jeremy所说的那样,确保所有项目Platforms都设置为Any CPU ,我们可以直接删除x64平台设置以进行干净的配置。


If you choose to set all project platform to x64, follow steps below. 如果您选择将所有项目平台设置为x64,请执行以下步骤。

VS consumes x86 runtime by default, to debug x64 functions we have to download x64 cli(containing runtime) and configure manually. VS默认使用x86运行时,要调试x64功能,我们必须下载x64 cli(包含运行时)并手动配置。

  1. Visit cli release note to download latest x64 bits(1.x for v1 .NET Framework Functions, 2.x for v2 .NET Core Functions). 请访问cli发行说明以下载最新的x64位(对于v1 .NET Framework函数,为1.x;对于v2 .NET Core函数,为2.x)。 For example, for v2 functions on OS Windows, we could choose Azure.Functions.Cli.min.win-x64.2.4.317 . 例如,对于OS Windows上的v2函数,我们可以选择Azure.Functions.Cli.min.win-x64.2.4.317

  2. Right click on your project->Properties, do debug configuration below. 右键单击您的项目->属性,在下面进行调试配置。

     Launch: Executable Executable: [x64CliPath]\\func.exe Application Arguments: host start 

    在此处输入图片说明

  3. Before publish, don't forget to modify Platform to 64-bit on Application settings in Azure portal. 发布之前,请不要忘记在Azure门户中的“应用程序”设置上将“平台”修改为64位。

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

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