dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.65k stars 1.05k forks source link

dotnet add project wrong configuration #17243

Open CHi-yas opened 3 years ago

CHi-yas commented 3 years ago

Some time ago I evaluated the usage of the .NET CLI. Which is really simple and easy to use. I used it to add several projects to a existing solution file. After building my solution on the build server i had a strange behavior. Even for release configuration the debug configuration was build. After some investigation I found out the useage of the .NET CLI caused the issue.

I reproduced it with an empty solution where I just wanted to add one project.

Empty solution:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
MinimumVisualStudioVersion = 10.0.40219.1
Global
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {BD04E6CD-1AA7-4995-8A25-E0559BC2E184}
    EndGlobalSection
EndGlobal

After adding the project manual with Visual Studio:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{8492F4EC-BE0F-439A-B28F-E5DB871C9F95}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {BD04E6CD-1AA7-4995-8A25-E0559BC2E184}
    EndGlobalSection
EndGlobal

Everything looks fine a configuration for Debug and Release is added.

If i try the same with the .NET Core-CLI:

dotnet sln ClassLibrary1.sln add ClassLibrary1/ClassLibrary1.csproj

The result is a little bit different from my expected result:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{8492F4EC-BE0F-439A-B28F-E5DB871C9F95}"
EndProject
Global
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {BD04E6CD-1AA7-4995-8A25-E0559BC2E184}
    EndGlobalSection
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Debug|x64 = Debug|x64
        Debug|x86 = Debug|x86
        Release|Any CPU = Release|Any CPU
        Release|x64 = Release|x64
        Release|x86 = Release|x86
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Debug|x64.ActiveCfg = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Debug|x64.Build.0 = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Debug|x86.ActiveCfg = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Debug|x86.Build.0 = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Release|Any CPU.ActiveCfg = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Release|Any CPU.Build.0 = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Release|x64.ActiveCfg = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Release|x64.Build.0 = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Release|x86.ActiveCfg = Debug|Any CPU
        {8492F4EC-BE0F-439A-B28F-E5DB871C9F95}.Release|x86.Build.0 = Debug|Any CPU
    EndGlobalSection
EndGlobal

The project was succesfully added but all configurations point to Debug. That is the explaination why also in Release configuration Debug is build.

I could reproduce this behavior on several machines. Also different colleagues can reproduce this behavior.

The .Net version is 5.0.202

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

CHi-yas commented 3 years ago

Microsoft has approved this problem. See: https://developercommunity2.visualstudio.com/t/dotnet-add-project-wrong-configuration/1410504?from=email&space=61&entry=problem

marcpopMSFT commented 3 years ago

I tried dotnet new classlib, dotnet new sln, dotnet sln test.sln add test.csproj and didn't see this behavior. Is there anything special in your csproj file that might indicate it only supports debug config?

CHi-yas commented 3 years ago

Hi,

I have also reported this behavior in the Microsoft forum. https://developercommunity.visualstudio.com/t/dotnet-add-project-wrong-configuration/1410504?from=email

They could reproduce this behavior and I have also added more detailed information.

Von: Marc Paine @.> Gesendet: Mittwoch, 26. Mai 2021 23:20 An: dotnet/sdk @.> Cc: Christian Heinz @.>; Author @.> Betreff: Re: [dotnet/sdk] dotnet add project wrong configuration (#17243)

I tried dotnet new classlib, dotnet new sln, dotnet sln test.sln add test.csproj and didn't see this behavior. Is there anything special in your csproj file that might indicate it only supports debug config?

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Fsdk%2Fissues%2F17243%23issuecomment-849126764&data=04%7C01%7Cchristian.heinz%40yaskawa.eu.com%7C33dd01467f294d4abe5708d9208c141a%7C7323b23de4294dc499b5726501252240%7C0%7C0%7C637576608281536924%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=ef1LuQl9XjePAwxTaPKLGLdIbMJaEi13%2FWbefMG5%2FUE%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAT3YBJH66FN37SNORAC4WNTTPVQZRANCNFSM43WJ4SGA&data=04%7C01%7Cchristian.heinz%40yaskawa.eu.com%7C33dd01467f294d4abe5708d9208c141a%7C7323b23de4294dc499b5726501252240%7C0%7C0%7C637576608281536924%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=mmH%2BGtQZsxioMVkaPQ5jQpavyLvyfFNzYqYa5I2Ie2E%3D&reserved=0.


Geschaeftsfuehrer/Managing Directors: Manfred Stern, Bruno J. Schnekenburger, Marcus Mead Amtsgericht/Local Court: Frankfurt, Commercial register no. 88369 Headquarters: YASKAWA Europe GmbH, Hauptstr. 185, D-65760 Eschborn

CONFIDENTIALITY: This e-mail and any attachments are confidential and may also be privileged. If you are not the named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose, or store or copy the information in any medium.