dotnet sln add doesn't support shared projects
See original GitHub issueDescribe the bug
We’re currently building support scripts for our projects which download a part of a repository (which contains shared and “normal” c# projects) and then adds all those csproj and shproj files to the targeted visual studio solution using the dotnet sln add command.
All csproj projects are getting added succesfully whereas all shproj projects aren’t. Doing the same in Visual Studio (via the IDE) the shproj projects are getting added.
The following error message appears:
Invalid project Path\XYZ.shproj. The imported project "C:\Program Files\dotnet\sdk\6.0.100\Microsoft\VisualStudio\v17.0\CodeSharing\Microsoft.CodeSharing.Common.Default.props" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\6.0.100\Microsoft\VisualStudio\v17.0\CodeSharing\Microsoft.CodeSharing.Common.Default.props" is correct, and that the file exists on disk.
For every import statement, in the shproj file, we’re getting somewhat the same error message.
When creating a new shared project in Visual Studio you get the following pre defined import statements:
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
I understand the cause since the values for the parameters MSBuildExtensionsPath and MSBuildExtensionsPath32 are different between MSBuild and dotnet.
dotnet resolves the paths to C:\Program Files\dotnet\sdk\6.0.100 whereas msbuild resolves them to C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\
It seems that dotnet sln add does validate the project before adding it to the solution if all import statements are valid.
Would it be possible to:
- Skip the validation?
- Feed in the parameters value
- dotnet sln add honors the target framework of the projects and falls back to msbuild (similar to dotnet build)
Is the concept of shared project being canceled from a dotnet core perspective?
Thanks in advance!
To Reproduce
- Open Visual Studio
- Create new solution
- Add shared project
- Save
- Open console
- Run dotnet sln remove path_to_shared_project
- Run dotnet sln add path_to_shared_project
Exceptions (if any)
See above
Further technical details
.NET SDK (reflecting any global.json): Version: 6.0.100 Commit: 9e8b04bbff
Runtime Environment: OS Name: Windows OS Version: 10.0.19043 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.100\
Host (useful for support): Version: 6.0.0 Commit: 4822e3c3aa
.NET SDKs installed: 6.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
IDEs: VS 2022 Preview 17.1.0 Preview 1.1
Issue Analytics
- State:
- Created 2 years ago
- Reactions:10
- Comments:18 (11 by maintainers)
Top GitHub Comments
Thank you for the quick response! In general I think we’re going to want to approve #22954 (or something like it) as pre-work necessary to support more kinds of projects at the CLI level, even if full support in the SDK isn’t quite there yet, but I want to confirm some details myself and discuss the support implication with the team before we go ahead much further.
Thank you for all of your work so far investigating, developing, and testing this scenario.
Are you able to get dotnet build working by creating a sln containing shproj using the 3 steps you mentioned?
I tried to dotnet build directly on a shproj and it wouldn’t pass with exists() on 3 props and 1 target, wondering if there’s a way to make it work directly without help of sln file.