简体   繁体   中英

No symbols loaded for a (.NET Framework 4.8) library in new csproj format when debugging a ASP.NET (.NET Framework 4.8) web application

I have a ASP.NET (.NET Framework 4.8) web application that we've been developing and evolving for many years.

I've spent some time converting many of the Class Libraries that it uses to the new csproj format but the class libraries are still targeting .NET Framework 4.8 (net48).

The application compiles and runs fine. However I've just tried investigating an issue and have found that when Debugging, the symbols are no longer loading for the converted class libraries and I can no longer step through the code in those class libraries.

A typical.csproj for the converted class libraries is as follows:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <ProductVersion>9.0.30729</ProductVersion>
        <SchemaVersion>2.0</SchemaVersion>
        <OutputType>Library</OutputType>
        <AppDesignerFolder>Properties</AppDesignerFolder>
        <TargetFramework>net48</TargetFramework>
        <SccProjectName>SAK</SccProjectName>
        <SccLocalPath>SAK</SccLocalPath>
        <SccAuxPath>SAK</SccAuxPath>
        <SccProvider>SAK</SccProvider>
        <Optimize>true</Optimize>
        <LangVersion>8.0</LangVersion>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <DebugType>full</DebugType>
        <DebugSymbols>true</DebugSymbols>
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="Microsoft.CSharp" />
        <Reference Include="System" />
        <Reference Include="System.ComponentModel.DataAnnotations" />
        <Reference Include="System.configuration" />
        <Reference Include="System.Core" />
        <Reference Include="System.Data" />
        <Reference Include="System.Drawing" />
        <Reference Include="System.Net.Http" />
        <Reference Include="System.Numerics" />
        <Reference Include="System.Runtime.Serialization" />
        <Reference Include="System.Security" />
        <Reference Include="System.Web" />
        <Reference Include="System.Xml" />
    </ItemGroup>
    <ItemGroup>
        <None Include="RSPlatform.Core.ruleset" />
        <None Include="Properties\DataSources\P42Entities.datasource" />
        <None Include=".editorconfig" />
        <None Include="App.Config">
            <SubType>Designer</SubType>
        </None>
        <EmbeddedResource Include="AssessmentPlus\TemplateInstall\Data\AssessmentSchema.xsd">
            <SubType>Designer</SubType>
        </EmbeddedResource>
    </ItemGroup>
    <ItemGroup>
        <EmbeddedResource Include="AssessmentPlus\TemplateInstall\Data\ImportInfo.xml" />
        <None Include="Properties\Settings.settings">
            <Generator>SettingsSingleFileGenerator</Generator>
            <LastGenOutput>Settings.Designer.cs</LastGenOutput>
        </None>
        <None Include="AssessmentPlus\TemplateInstall\Data\WA_Test_MiniAssessment.xml" />
        <None Include="AssessmentPlus\TemplateInstall\Data\WA_Test_NumberedAssessment.xml" />
        <EmbeddedResource Include="AssessmentPlus\TemplateInstall\Data\StandardAssessment.xml" />
    </ItemGroup>
    <ItemGroup>
        <EmbeddedResource Include="AssessmentPlus\TemplateInstall\Data\WA_AtosAssessment_v5.xml" />
    </ItemGroup>
    <ItemGroup>
        <ProjectReference Include="..\RSPlatform.Common\RSPlatform.Common.csproj" />
        <ProjectReference Include="..\RSPlatform.Crypt\RSPlatform.Crypt.csproj" />
        <ProjectReference Include="..\RSPlatform.Data.Core\RSPlatform.Data.Core.csproj" />
        <ProjectReference Include="..\RSPlatform.Mail\RSPlatform.Mail.csproj" />
    </ItemGroup>
    <ItemGroup>
        <EmbeddedResource Include="AssessmentPlus\TemplateInstall\Data\DA_Standard.xml">
            <SubType>Designer</SubType>
        </EmbeddedResource>
        <Content Include="AssessmentPlus\TemplateInstall\Data\Template-Text-Extract.xslt" />
        <EmbeddedResource Include="AssessmentPlus\TemplateInstall\Data\WA_Standard.xml" />
        <Content Include="AssessmentPlus\TemplateInstall\Data\Template-HTML-Extract.xslt" />
    </ItemGroup>
    <ItemGroup>
        <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
    </ItemGroup>
    <ItemGroup>
        <PackageReference Include="EntityFramework" Version="6.4.0" />
        <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
        <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" />
        <PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="3.0.0" />
        <PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="3.0.0" />
        <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.3" />
        <PackageReference Include="Microsoft.NetCore.Analyzers" Version="3.0.0" />
        <PackageReference Include="Microsoft.NetFramework.Analyzers" Version="3.0.0" />
        <PackageReference Include="RealSense.DomainBasedConfig" Version="1.2.0" />

        <PackageReference Include="AutoMapper" Version="9.0.0" />
        <PackageReference Include="iTextSharp" Version="5.5.13.1" />
        <PackageReference Include="LinqKit" Version="1.1.17" />
        <PackageReference Include="Mehdime.Entity" Version="1.0.0" />
        <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
        <PackageReference Include="Ninject" Version="3.3.4" />
    </ItemGroup>
</Project>

The unchanged ASP.NET web application is still in the legacy format as Microsoft still haven't brought in support for the new csproj format (despite talk of doing so several years ago). it looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="..\..\..\..\..\..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.3.0.0\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props" Condition="Exists('..\..\..\..\..\..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.3.0.0\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" />
  <Import Project="..\..\..\..\..\..\packages\Microsoft.NetFramework.Analyzers.3.0.0\build\Microsoft.NetFramework.Analyzers.props" Condition="Exists('..\..\..\..\..\..\packages\Microsoft.NetFramework.Analyzers.3.0.0\build\Microsoft.NetFramework.Analyzers.props')" />
  <Import Project="..\..\..\..\..\..\packages\Microsoft.NetCore.Analyzers.3.0.0\build\Microsoft.NetCore.Analyzers.props" Condition="Exists('..\..\..\..\..\..\packages\Microsoft.NetCore.Analyzers.3.0.0\build\Microsoft.NetCore.Analyzers.props')" />
  <Import Project="..\..\..\..\..\..\packages\Microsoft.CodeQuality.Analyzers.3.0.0\build\Microsoft.CodeQuality.Analyzers.props" Condition="Exists('..\..\..\..\..\..\packages\Microsoft.CodeQuality.Analyzers.3.0.0\build\Microsoft.CodeQuality.Analyzers.props')" />
  <Import Project="..\..\..\..\..\..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.3.0.0\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props" Condition="Exists('..\..\..\..\..\..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.3.0.0\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" />
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <Import Project="C:\packages\EntityFramework.6.4.0\build\EntityFramework.props" Condition="Exists('C:\packages\EntityFramework.6.4.0\build\EntityFramework.props')" />
  <Import Project="C:\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('C:\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{52F85C76-86BD-4924-BD61-8ECF32D9075A}</ProjectGuid>
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>PlatformNET</RootNamespace>
    <AssemblyName>PlatformNET</AssemblyName>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
    <UseIISExpress>true</UseIISExpress>
    <FileUpgradeFlags>
    </FileUpgradeFlags>
    <UpgradeBackupLocation>
    </UpgradeBackupLocation>
    <OldToolsVersion>4.0</OldToolsVersion>
    <IISExpressSSLPort>44328</IISExpressSSLPort>
    <IISExpressAnonymousAuthentication />
    <IISExpressWindowsAuthentication />
    <IISExpressUseClassicPipelineMode />
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
    <TargetFrameworkProfile />
    <UseGlobalApplicationHostFile />
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
    <Use64BitIISExpress />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE;DEBUG</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PublishDatabases>false</PublishDatabases>
    <Prefer32Bit>false</Prefer32Bit>
    <DocumentationFile>
    </DocumentationFile>
    <NoWarn>CA1303;CA1308;CA1028;CA1056;CA1707;CA1031;CA1710;CA1305</NoWarn>
    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    <LangVersion>default</LangVersion>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <FilesToIncludeForPublish>OnlyFilesToRunTheApp</FilesToIncludeForPublish>
    <PackageAsSingleFile>true</PackageAsSingleFile>
    <PrecompileBeforePublish>true</PrecompileBeforePublish>
    <UseMerge>true</UseMerge>
    <WDPMergeOption>MergeAllOutputsToASingleAssembly</WDPMergeOption>
    <EnableUpdateable>false</EnableUpdateable>
    <SingleAssemblyName>MyPrecompiled</SingleAssemblyName>
    <PublishDatabases>false</PublishDatabases>
    <ExcludeApp_Data>false</ExcludeApp_Data>
    <Prefer32Bit>false</Prefer32Bit>
    <DocumentationFile>
    </DocumentationFile>
    <NoWarn>CA1303;CA1308;CA1028;CA1056;CA1707;CA1031;CA1710;CA1305</NoWarn>
    <CodeAnalysisRuleSet>PlatformNET.ruleset</CodeAnalysisRuleSet>
    <LangVersion>default</LangVersion>
  </PropertyGroup>
 ...
  <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="AfterBuild" Condition="Exists('Web.$(Configuration).config')">
    <!--Generate transformed config in the output directory-->
    <TransformXml Source="Web.config" Destination="$(OutputPath)Web.config" Transform="Web.$(Configuration).config" />
  </Target>
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('C:\packages\EntityFramework.6.4.0\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', 'C:\packages\EntityFramework.6.4.0\build\EntityFramework.props'))" />
    <Error Condition="!Exists('C:\packages\EntityFramework.6.4.0\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', 'C:\packages\EntityFramework.6.4.0\build\EntityFramework.targets'))" />
    <Error Condition="!Exists('C:\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', 'C:\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
    <Error Condition="!Exists('..\..\..\..\..\..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.3.0.0\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.3.0.0\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props'))" />
    <Error Condition="!Exists('..\..\..\..\..\..\packages\Microsoft.CodeQuality.Analyzers.3.0.0\build\Microsoft.CodeQuality.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\..\packages\Microsoft.CodeQuality.Analyzers.3.0.0\build\Microsoft.CodeQuality.Analyzers.props'))" />
    <Error Condition="!Exists('..\..\..\..\..\..\packages\Microsoft.NetCore.Analyzers.3.0.0\build\Microsoft.NetCore.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\..\packages\Microsoft.NetCore.Analyzers.3.0.0\build\Microsoft.NetCore.Analyzers.props'))" />
    <Error Condition="!Exists('..\..\..\..\..\..\packages\Microsoft.NetFramework.Analyzers.3.0.0\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\..\packages\Microsoft.NetFramework.Analyzers.3.0.0\build\Microsoft.NetFramework.Analyzers.props'))" />
    <Error Condition="!Exists('..\..\..\..\..\..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.3.0.0\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.3.0.0\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
  </Target>
  <Import Project="C:\packages\EntityFramework.6.4.0\build\EntityFramework.targets" Condition="Exists('C:\packages\EntityFramework.6.4.0\build\EntityFramework.targets')" />
</Project>   

Is there any way I can get the class libraries to work fully in the debugger? or am I going to have to have a little rage and then "undo" all that conversion work?

EDIT: So on a separate machine I created a NEW ASP.NET Framework Web App and two class libraries (a .NET Framework 4.7.2 and a .NET Standard 2.1 one). I was able to step into both class libraries so this appears not to be due to new csproj format itself.

Back on my problematic solution, I can see teh .NET Standard Class lib has a.PDF file in the bin folder but the Debugger output is showing:

Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled

Just My Code is enabled, however I think the "Module is optimized" is the real issue. I'm compiling as DEBUG not RELEASE. Any idea on what I need to change in the ".NET Standard Class Lib".csproj file to compile DEBUG versions without optimisations?

Thanks Chris

So, as stated in the opening question the Build Output shows that these modules don't load symbols because the output was "optimized" (GB optimised).

The Build Tab of Project Properties page includes two checkboxes: "Define DEBUG constant" and "Optimize code". The first was unchecked and the second was checked when looking at the DEBUG configuration.

Reversing both of these (DEBUG configuration) fixed the issue raised. However, the "Optimize Code" doesn't appear to be configuration specific, and looking at the underlying csproj file after the change I can see that it's defined outside a configuration:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        ...
        <TargetFramework>net48</TargetFramework>
        <Optimize>false</Optimize>                  <-- Not Configuration specific
        <LangVersion>8.0</LangVersion>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <DebugType>full</DebugType>
        <DebugSymbols>true</DebugSymbols>
        <DefineConstants>DEBUG</DefineConstants>    <-- Configuration specific
    </PropertyGroup>

I found that I could add a "Release|AnyCPU" configuration/platform and move the <Optimize> value in each version fix this:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <ProductVersion>9.0.30729</ProductVersion>
        <SchemaVersion>2.0</SchemaVersion>
        <OutputType>Library</OutputType>
        <AppDesignerFolder>Properties</AppDesignerFolder>
        <TargetFramework>net48</TargetFramework>
        <SccProjectName>SAK</SccProjectName>
        <SccLocalPath>SAK</SccLocalPath>
        <SccAuxPath>SAK</SccAuxPath>
        <SccProvider>SAK</SccProvider>        <-- Removed <Optimize> from here
        <LangVersion>8.0</LangVersion>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">    <-- ADDED
        <DebugType>full</DebugType>
        <DebugSymbols>true</DebugSymbols>
        <Optimize>true</Optimize>             <-- ADDED
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <DebugType>full</DebugType>
        <DebugSymbols>true</DebugSymbols>
        <DefineConstants>DEBUG</DefineConstants>
        <Optimize>false</Optimize>            <-- ADDED
    </PropertyGroup>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM