deps.json not published for projects referenced for XUnit Integration Tests project.

Bhanu Prakash Thunuguntla 31 Reputation points
2020-11-26T22:38:03.76+00:00

I have a visual studio solution with two projects, both are using .NET Core 3.1

  1. Xyz.Api
  2. Xyz.ApiTests

ApiTests is a XUnit project for integration testing and has a PROJECT REFERENCE to Xyz.Api project

I have followed what is mentioned here. Integration Tests in .NET Core

This is what ApiTests.csproj looks like.

<Project Sdk="Microsoft.NET.Sdk.Web">  
  
  <PropertyGroup>  
    <TargetFramework>netcoreapp3.1</TargetFramework>  
    <IsPackable>false</IsPackable>  
  </PropertyGroup>  
  
  <ItemGroup>  
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.10" />  
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.10" />  
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.1.10" />  
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.10" />  
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.10" />  
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.10" />  
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />  
    <PackageReference Include="Moq" Version="4.14.7" />  
    <PackageReference Include="System.Net.Http.Json" Version="5.0.0" />  
    <PackageReference Include="xunit" Version="2.4.1" />  
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">  
      <PrivateAssets>all</PrivateAssets>  
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>  
    </PackageReference>  
    <PackageReference Include="coverlet.collector" Version="1.3.0">  
      <PrivateAssets>all</PrivateAssets>  
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>  
    </PackageReference>  
  </ItemGroup>  
  
  <ItemGroup>  
    <ProjectReference Include="..\..\Xyz.Api\Xyz.Api.csproj" />  
  </ItemGroup>  
  
  <ItemGroup>  
    <None Update="appsettings.json">  
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>  
    </None>  
  </ItemGroup>  
  
</Project>  

Iam able to run the XUnit integration tests using Visual Studio.
On Release build, the bin folder has both files - Xyz.Api.deps.json and Xyz.ApiTests.deps.json

But on Publish, the PUBLISH folder has only one file - Xyz.ApiTests.deps.json; and the Xyz.Api.deps.json file is missing.

When I run dotnet test Xyz.ApiTests from PUBLISH folder, Iam getting the following error.

Can't find'D:......\Xyz.ApiTests\Xyz.Api.deps.json'. This file is required for functional tests to run properly. There should be a copy of the file on your source project bin folder. If that is not the case, make sure that the property PreserveCompilationContext is set to true on your project file. E.g '<PreserveCompilationContext>true</PreserveCompilationContext>'. For functional tests to work they need to either run from the build output folder or the ReleaseManagement.Api.deps.json file from your application's output directory must be copied to the folder where the tests are running on. A common cause for this error is having shadow copying enabled when the tests run.

How to make sure the file Xyz.Api.deps.json is also copied to PUBLISH folder on PUBLISH PROJECT?
Any help please?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,199 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,292 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,125 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bhanu Prakash Thunuguntla 31 Reputation points
    2020-11-27T09:04:27.39+00:00

    Xyz.Api.csproj file content is here.

    Xyz.Api.csproj file content is here.
    
    
        <Project Sdk="Microsoft.NET.Sdk.Web">
    
          <PropertyGroup>
            <TargetFramework>netcoreapp3.1</TargetFramework>
            <UserSecretsId>a0979ad4-2dd4-46cf-9433-eb5f5de4da3d</UserSecretsId>
            <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
            <DockerfileContext>..\..</DockerfileContext>
          </PropertyGroup>
            <PropertyGroup>
                <LangVersion>latest</LangVersion>
            </PropertyGroup>
          <ItemGroup>
            <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
            <PackageReference Include="MediatR" Version="9.0.0" />
            <PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
            <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.15.0" />
            <PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.1.2" />
            <PackageReference Include="Microsoft.ApplicationInsights.Kubernetes.HostingStartup" Version="1.1.2" />
            <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.8" />
            <PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureKeyVault" Version="3.1.8" />
            <PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureStorage" Version="3.1.8" />
            <PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="2.2.0" />
            <PackageReference Include="Microsoft.Azure.ServiceBus" Version="5.0.0" />
            <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.8" />
            <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8">
              <PrivateAssets>all</PrivateAssets>
              <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            </PackageReference>
            <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.8" />
            <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.8" />
            <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
            <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
            <PackageReference Include="MongoDB.Driver" Version="2.11.2" />
            <PackageReference Include="Polly" Version="7.2.1" />
            <PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
            <PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0" />
            <PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" />
            <PackageReference Include="System.Collections" Version="4.3.0" />
            <PackageReference Include="System.Runtime" Version="4.3.1" />
          </ItemGroup>
          <ItemGroup>
            <ProjectReference Include="..\ReleaseManagement.Deployment\ReleaseManagement.Deployment.csproj" />
            <ProjectReference Include="..\ReleaseManagement.DevOps.Client\ReleaseManagement.DevOps.Client.csproj" />
          </ItemGroup>
    
        </Project>
    
    0 comments No comments

  2. Anonymous
    2021-05-28T05:19:11.413+00:00

    Hi,

    I am also facing same problem , did you got this working ?

    0 comments No comments