umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.43k stars 2.67k forks source link

appsettings.Local.json is not copied to output directory when using Umbraco.Cms.Tests.Integration #16032

Open lars-erik opened 5 months ago

lars-erik commented 5 months ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.*

Bug summary

The Umbraco.Cms.Tests.Integration nuget package adds a linked appsettings.Local.json file.
However it must be set to copy to output directory manually for it to "work".
It's also linked to the user specific nuget cache folder, so it would be super if it points to $(NuGetPackageRoot) instead.

I've looked around the source, but cannot for the life of me figure out how/where the file is included in the package. 🙈

Specifics

No response

Steps to reproduce

Install Umbraco.Cms.Tests.Integration.
Derive a class from UmbracoIntegrationTest.
Add a test to it.
See if it runs.

(Also have to inherit GlobalSetupTeardown and mark it as SetUpFixture ofc.)

Expected result / actual result

No response

github-actions[bot] commented 5 months ago

Hi there @lars-erik!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

NguyenThuyLan commented 2 months ago

Hi @lars-erik , can you describe more details about your expected result? I'm not sure if you're referring to the appsettings.Local.json or appsettings.Tests.json file?

lars-erik commented 1 month ago

It's about the appsettings.Tests.json file.

In the core integration test project it is "correctly" set up.
https://github.com/umbraco/Umbraco-CMS/blob/e8051978e975deafe57511d8939c003ea2347a94/tests/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj#L54

When the package is installed in a project however, the linked file loses its CopyToOutputDirectory attribute. It's only linked as content and that makes it so it isn't copied on build and the tests won't run.
We can manually set the attribute back, but then Visual Studio will point to the local user's nuget cache:

  <ItemGroup>
    <Content Update="C:\Users\[my user name]\.nuget\packages\umbraco.cms.tests.integration\14.2.0\contentFiles\any\net8.0\appsettings.Tests.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

The path can then manually be set to $(NugetPackageRoot)\umbraco.cms.tests.integration\14.2.0\contentFiles\any\net8.0\appsettings.Tests.json.

Both these steps would be unnecessary if the nuget package could provide the copy to output attribute.
ATM I don't know how to do that, otherwise I'd make a PR.