Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exception message if deps.json not found when using WebApplicationFactory<T> #29892

Open
martincostello opened this issue Feb 4, 2021 · 5 comments

Comments

@martincostello
Copy link
Contributor

@martincostello martincostello commented Feb 4, 2021

Is your feature request related to a problem? Please describe.

When using the WebApplicationFactory<T> class in tests, if the Microsoft.AspNetCore.Mvc.Testing NuGet package is referenced transitively, rather than directly in the test project, then an exception may be thrown with this message if the deps.json file of the assembly containing the startup class T isn't otherwise somehow copied to the test output folder:

<data name="MissingDepsFile" xml:space="preserve">
<value>Can't find '{0}'. 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 '&lt;PreserveCompilationContext&gt;true&lt;/PreserveCompilationContext&gt;'. For functional tests to work they need to either run from the build output folder or the {1} 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.</value>
</data>

The resolution is to add a direct reference to Microsoft.AspNetCore.Mvc.Testing in the project file so that the target to copy the .deps.json files during the build are run:

<Target Name="_MvcCopyDependencyFiles" AfterTargets="Build;_ResolveMvcTestProjectReferences" Condition="'$(TargetFramework)'!=''">
<ItemGroup>
<DepsFilePaths
Condition="'%(_ContentRootProjectReferences.Identity)' != ''"
Include="$([System.IO.Path]::ChangeExtension('%(_ContentRootProjectReferences.ResolvedFrom)', '.deps.json'))" />
</ItemGroup>
<Copy SourceFiles="%(DepsFilePaths.FullPath)" DestinationFolder="$(OutDir)" Condition="Exists('%(DepsFilePaths.FullPath)')" />
</Target>

Describe the solution you'd like

Preferred solution: if possible, the target runs even when the NuGet package is included as a transient dependency.

Alternative solution: Update the error message to include checking that Microsoft.AspNetCore.Mvc.Testing is explicitly referenced in the tests' project file.

@javiercn
Copy link
Contributor

@javiercn javiercn commented Feb 4, 2021

@martincostello thanks for contacting us.

We don't expect people to reference this package transitively, but I would be ok if we update it for the targets to be loaded when referenced transitively.

The change here would be to add a \buildTransitive folder to the package with props/targets that import the ones within the \build directory.

@msftbot
Copy link
Contributor

@msftbot msftbot bot commented Feb 4, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@martincostello
Copy link
Contributor Author

@martincostello martincostello commented Feb 4, 2021

Cool thanks @javiercn - I'd be happy to pick that up a do a PR to make the change.

@javiercn
Copy link
Contributor

@javiercn javiercn commented Feb 4, 2021

@martincostello we would be happy to accept a PR for it.

@javiercn
Copy link
Contributor

@javiercn javiercn commented Feb 4, 2021

Thanks!

martincostello added a commit to martincostello/aspnetcore that referenced this issue Feb 5, 2021
Add a buildTransitive targets file to load the main MSBuild
targets so that transitive references to the package will also
run the target to copy the deps.json files.

Resolves dotnet#29892.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants