I\'m setting up an ASP.NET Core project on TeamCity. The binaries it builds crash on startup on other machines. The error message shows that it is looking for dlls in paths
*.deps.json
comes from preserveCompilationContext
.
Preserving the compilation context is useful for runtime compilation (i.e. just-in-time compilation) and especially for compiling views. It is not usually useful for libraries. To fix your problem:
preserveCompilationContext
from each Company.*
library that your app references.preserveCompilationContext
from your main app.There is an involved conversation here: https://github.com/aspnet/Mvc/issues/5141
The answer to your first question, per the Runtime Configuration File Documentation:
And the answer to your second question, is to remove preserveCompilationContext in your project.json file (and rebuild).
MyApp.deps.json is a list of dependencies, as well as compilation context data and compilation dependencies. Not technically required, but required to use the servicing or package cache/shared package install features.
Per your comment to Dimitry, I couldn't tell if you have .net core installed in your target machine and therefore infer the kind of deployment you are trying to do. But assuming it is installed, you should be able to tune your myproject.runtime.json to fix your problems. In case you don't, I highly recommend reading about the two different types of .NET Core Application Deployment:
You can create two types of deployments for .NET Core applications:
Framework-dependent deployment. As the name implies, framework-dependent deployment (FDD) relies on a shared system-wide version of .NET Core to be present on the target system. Because .NET Core is already present, your app is also portable between installations of .NET Core. Your app contains only its own code and any third-party dependencies that are outside of the .NET Core libraries. FDDs contain .dll files that can be launched by using the dotnet utility from the command line. For example, dotnet app.dll runs an application named app.
Self-contained deployment. Unlike FDD, a self-contained deployment (SCD) does not rely on any shared components to be present on the target system. All components, including both .NET Core libraries and the .NET Core runtime, are included with the application and are isolated from other .NET Core applications. SCDs include an executable (such as app.exe on Windows platforms for an application named app), which is a renamed version of the platform-specific .NET Core host, and a .dll file (such as app.dll), which is the actual application.
If you are using the newer .csproj format
Adding <PreserveCompilationContext>false</PreserveCompilationContext>
under the <TargetFramework>
tag fixed the issue for me.
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>false</PreserveCompilationContext>
</PropertyGroup>
After a full search finally found my solution, this was my case: - only happens when run
dotnet publish
so in order to solve this, edit your csproj and make sure to have this configuration.
This apply to webapi netcoreapp 2.0
<PropertyGroup>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
<PreserveCompilationContext>false</PreserveCompilationContext>
</PropertyGroup>
this also will solve problems related to
"error CS0246: The type or namespace name 'System' could not be found"
ref.: https://github.com/aspnet/MvcPrecompilation/issues/162 https://github.com/dotnet/dotnet-docker/issues/279