简体   繁体   中英

Referencing ASP.NET Core 2 project from another ASP.NET Core 2 project fails when publishing

In order to split controllers for separate sub projects within a large web application i created another ASP.NET Core 2 web project and referenced it from my main Web project. The Projects use ASP.NET Core running on full .NET Framework 4.7.1.

In the second project i put additional controllers and an extension method for service registrations.

I only had to change the output type of the second web project to class library and everything worked fine during development.

However, when i try to publish the web application to azure, i get this error:

Metadata file 'E:\Dev\MyProject\MyProject.SecondWebProject\bin\Release\net471\win7-x86\MyProject.SecondWebProject.dll' could not be found   

A message box stated that additional information is available in a log file. The content from this log file is this:

System.AggregateException: One or more errors occurred. ---> System.Exception: Publish failed due to build errors. Check the error list for more details.
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Web.Publish.PublishService.VsWebProjectPublish.<>c__DisplayClass40_0.<PublishAsync>b__2()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ApplicationCapabilities.Publish.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__88.MoveNext()
---> (Inner Exception #0) System.Exception: Publish failed due to build errors. Check the error list for more details.<---

The output of my second web project doesn't get copied over to the \\win7-x86 folder but it's available in the \\Debug and \\Release folders where output gets emitted during local builds.

I'm using Visual Studio 2017 (Update 15.6.3) and tried the following:

  • Clean Solution / Rebuild everything
  • Remove project reference to second Web Project and add it again
  • Making sure, both of the projects have the same Platform Target

Creating an ordinary class library is not my favorable option because i want to use the meta package support i have in my main web project. Otherwise having tons of package references would be a bit of a pain of keeping in sync with my main project i fear.

Thanks a lot for your help!

I have got the same problem when I publish .net core web app which is referencing another project.

I manually deleted the bin and obj folder and rebuilt the project and that solved it.

Well i basically solved it by adding an ordinary class library targeting full .NET Framework, added ASP.NET Core Dependencys and used the following code to make ASP.NET Core aware of the assembly:

var secondWebProject = typeof(SecondWebProjectController).Assembly;
services.AddMvc().AddApplicationPart(secondWebProject);

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