57

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 that only exist on the build server. DotPeek shows that there's an embedded resource file in the .exe called myproject.deps.json. In the targets section there, there are references to dlls using absolute paths. This means that ASP.NET Core binaries are only ever going to run on the machine on which they were built.

How do I fix this problem? What is this file, and how do I make it use relative paths? After some digging, it looks like the paths come from project.fragment.lock.json, which is a generated file. If I edit this to use relative paths, the file is just overwritten again. What generates this, and how can it be fixed, or stopped?

For those who asked, project.json looks like:

{
  "dependencies": {
    "CommandLineParser": "1.9.71",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "System.Configuration.Abstractions": "1.0.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "net461": {
      "dependencies": {
        "Company.Common": {
          "target": "project"
        },
        "Company.Integration": {
          "target": "project"
        },
        "Company.Functions": {
          "target": "project"
        },
        "Company.Utils": {
          "target": "project"
        }
      }
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
7
  • Those absolute path references are to third party libraries?
    – Evk
    Dec 1, 2016 at 15:10
  • @Evk Some of them, others are references to in house libraries.
    – TarkaDaal
    Dec 1, 2016 at 15:12
  • Is TeamCity installed on your machine, or on separate server? Is dotnet version is up-to-date? What part of deps.json contain path to libraries - can you compare with locally-build one and show us some differences?
    – Dmitry
    Dec 1, 2016 at 15:47
  • @Dmitry TeamCity is installed on a build server. Yes, .NET Core was installed yesterday. It's the targets section of deps.json. The only difference is the paths.
    – TarkaDaal
    Dec 1, 2016 at 16:03
  • Does your project name contain whitespace? Can you post your project.json?
    – Hypnobrew
    Dec 4, 2016 at 17:33

5 Answers 5

21

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.

4
  • I don't have a myapp.deps.json on disk. It's being automatically generated by (I assume) VS, and embedded in the application.
    – TarkaDaal
    Dec 5, 2016 at 10:27
  • 3
    @TarkaDaal if you want to get rid of myproject.deps.json in your assembly, you can remove preserveCompilationContext in your project.json file (and rebuild).
    – ciriarte
    Dec 5, 2016 at 17:57
  • @ciriate That was it! Make this an answer and you can can the bounty.
    – TarkaDaal
    Dec 6, 2016 at 10:29
  • Updated link: github.com/dotnet/sdk/blob/main/documentation/specs/…
    – djm
    Feb 15, 2022 at 16:04
18
+250

*.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:

  1. Remove preserveCompilationContext from each Company.* library that your app references.
  2. If that does not work, also remove preserveCompilationContext from your main app.

There is an involved conversation here: https://github.com/aspnet/Mvc/issues/5141

2
  • 5
    I added this in my netstandard2.0 project and still get deps.json
    – T.S.
    Oct 25, 2019 at 5:18
  • I added this in my net6.0 project and still get deps.json
    – farosch
    Dec 16, 2021 at 16:27
13

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>
3
  • 11
    I added this in my netstandard2.0 project and still get deps.json
    – T.S.
    Oct 25, 2019 at 5:17
  • 2
    I added this in my net6.0 project and still get deps.json
    – farosch
    Dec 16, 2021 at 16:27
  • Such elements are independent and Under has no effect.
    – AhmadYo
    Aug 28, 2022 at 7:12
2

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

1
  • God bless you! Worked on my .net framework 4.7.2.
    – oBit91
    Dec 28, 2020 at 10:04
1

I had the following error message:

An assembly specified in the application dependencies manifest (MyApp.deps.json) was not found: package: 'PropertyChanged.Fody', version: '3.4.0' path: 'lib/netstandard2.1/PropertyChanged.dll'

I found the solution here

In csrpoj you need

            <PackageReference Include="PropertyChanged.Fody" Version="3.4.0" PrivateAssets="All">
                <ExcludeAssets>runtime</ExcludeAssets>
                <IncludeAssets>All</IncludeAssets>
            </PackageReference>
1
  • That was the only solution that worked for me. I was having the same problem trying to run xUnit tests with Resharper using net6.0 and Anotar.Fody.
    – dougcunha
    Dec 28, 2021 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.