首页 > 解决方案 > dotnet 添加项目配置错误

问题描述

前段时间我评估了 .NET Core-CLI 的使用情况。这非常简单易用。我用它将几个项目添加到现有的解决方案文件中。在构建服务器上构建我的解决方案后,我有一个奇怪的行为。即使对于发布配置,也会构建调试配置。经过一番调查,我发现 .NET Core-CLI 的使用导致了这个问题。

我用一个空的解决方案复制了它,我只想添加一个项目。

空解决方案:

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

使用 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

一切看起来都很好,添加了 Debug 和 Release 的配置。

如果我尝试使用 .NET Core-CLI:

dotnet sln ClassLibrary1.sln add ClassLibrary1/ClassLibrary1.csproj

结果与我的预期结果有点不同:

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

项目已成功添加,但所有配置都指向 Debug。这就是为什么还要在发布配置中构建调试的解释。

有人解释这种行为还是我做错了什么?

.Net Core 版本为 3.1.408.15681

标签: .netcommand-line-interface

解决方案



推荐阅读