-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
dotnet sln add does not work for projects with extension .msbuildproj #11292
Comments
TLDR / Current WorkaroundIf you own the custom SDK you are importing and you want to have a custom file extension, then set the <Project>
<PropertyGroup>
<DefaultProjectTypeGuid>{2F08BC15-189B-4804-B644-653F34C968A8}</DefaultProjectTypeGuid>
</PropertyGroup>
</Project>
If you don't own the custom SDK and can't make changes to it, then add a <Project Sdk="MyCustom.Sdk">
<PropertyGroup>
<ProjectTypeGuids>{2F08BC15-189B-4804-B644-653F34C968A8}</ProjectTypeGuids>
</PropertyGroup>
</Project>
ResearchCurrently the dotnet CLI gives an error when trying to add a project to a solution that has an The error is being set at this location because the project type GUID is null. sdk/src/Cli/dotnet/SlnFileExtensions.cs Lines 64 to 71 in a30e465
The project type GUID is set to null here because the project root element does not have a sdk/src/Cli/dotnet/SlnFileExtensions.cs Line 59 in a30e465
sdk/src/Cli/dotnet/ProjectRootElementExtensions.cs Lines 11 to 22 in a30e465
sdk/src/Cli/dotnet/ProjectInstanceExtensions.cs Lines 23 to 26 in d220330
Different project SDKs in the dotnet SDK set the See the below example of one place where the sdk/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CrossTargeting.targets Lines 104 to 109 in c53c8ac
Originally I was going to do a pull request with the fix for this after line 42 below. That would allow it to fallback after the language targets and the cross targeting target referenced above would run. sdk/src/Tasks/Microsoft.NET.Build.Tasks/sdk/Sdk.targets Lines 37 to 42 in 172b214
While this did work for project files using a dotnet SDK, it didn't work for project files targeting custom SDKs like Microsoft.Build.NoTargets. For the fallback to apply to all projects regardless of SDK, I believe this would need to be added somewhere in MSBuild. I'm currently having trouble finding the best place to put this in MSBuild as the prop and target imports are hard to follow. If anyone has any ideas let me know below. See also |
I see the sln file format requires a project type GUID. Does the choice of GUID have any effects on command-line tools such as MSBuild and NuGet? |
@KalleOlaviNiemitalo I looked through the DotNet SDK and MSBuild and didn't see anywhere that uses these project type GUIDs other than for the solution file, so I don't think it matters what GUID you choose as long as it is unique. I think Visual Studio may use these GUIDs in some way for example to enable/disable tooling for different workloads, but I can't be sure of that. |
@KalleOlaviNiemitalo If you use the Microsoft.Build.NoTargets SDK and need multitargeting, and you want to be able to open and build in Visual Studio, then the GUID you choose may be important. See this comment and thread for more info: microsoft/MSBuildSdks#155 (comment) |
Steps to reproduce
dotnet new sln
.msbuildproj
(Foo.msbuildproj):dotnet sln add Foo.msbuildproj
Expected behaviour
Actual behaviour
The text was updated successfully, but these errors were encountered: