dotnet / templating

This repo contains the Template Engine which is used by dotnet new
https://docs.microsoft.com/dotnet/
MIT License
1.64k stars 370 forks source link

Adding a project reference fails from Visual Studio #7779

Open adcloeshelle opened 7 months ago

adcloeshelle commented 7 months ago

Product

Visual Studio

Describe The Bug

I am unable to get the "Add a project reference" post action to work when creating a new project via Visual Studio if the project is outside of the template folder. Using the dotnet cli works as expected, but using Visual Studio fails to add the reference and I see errors in the Visual Studio application log like:

817 ERROR Unable to add project reference, C:\ReferenceDemo\src\ClassLibrary1\ClassLibrary1.csproj not found. AddReferencePostCreationAction -- AddReferenceToProjectFileAsync 2024/03/28 19:28:12.402

Even though that path definitely exists.

To Reproduce

Steps: Use the attached demo project

  1. Put the ReferenceDemo folder at the root of the C:/ drive
  2. Run dotnet pack in C:/ReferenceDemo/templates
  3. Run dotnet new install C:/ReferenceDemo/templates/bin/Release/Templates.1.0.0.nupkg
  4. Create a new project with the custom template via the dotnet cli (dotnet new AppTemplate). Note that the created project correctly references ClassLibrary1
  5. Create a new project with the custom template via Visual Studio. Note that the created project does not have any project references. ReferenceDemo.zip

dotnet Info

output .NET SDK: Version: 8.0.200 Commit: 438cab6a9d Workload version: 8.0.200-manifests.e575128c Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.200\ .NET workloads installed: There are no installed workloads to display. Host: Version: 8.0.2 Architecture: x64 Commit: 1381d5ebd2 .NET SDKs installed: 3.1.117 [C:\Program Files\dotnet\sdk] 3.1.426 [C:\Program Files\dotnet\sdk] 8.0.200 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download

Visual Studio Version

17.9.1

Additional context

No response

david-acm commented 6 months ago

I think this is related to dotnet/sdk #40132 and #7833.

I proposed a fix in https://github.com/dotnet/sdk/issues/40132

Short explanation is that the template engine doesn't find files that it didin't create. Long in this discussion here