添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

I am using dotnet publish to publish my dotnet core 2.2 web application. I notice that the published folder has several unrequired files, specifically .pdbs, .appsettings.Development, .runtimeconfig.dev etc.

Qn: Is there a way dotnet publish command can be made to exclude these files or would I have to delete these manually?

Thanks

Using Property group in .csproj with <DebugType>None</DebugType> and <DebugSymbols>false</DebugSymbols> must be done on each referenced .csproj to apply on each referenced assemblies.

Using dotnet publish parameters /p:DebugType=None /p:DebugSymbols=false apply on each referenced assemblies.

YounesCheikh, danilobreda, Sibusten, LevYas, YZahringer, sbrockway, sboulema, igorgomeslima, aancag, patbec, and 15 more reacted with thumbs up emoji ahdung and Amberg reacted with thumbs down emoji All reactions

I want to point at the inconsistency of how the parameters applied: I tried to specify

<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>

In my \PublishProfiles\FolderProfile.pubxml, it works only for the project you publish, not for references.
I tried to do as @ducalai suggested - added publish parameters /p:DebugType=None /p:DebugSymbols=false and it worked for references too.
BTW the same thing with -p:Configuration=Release

  • I want .pdb in release folder but not in publish.
  • I don't want use DebugType for each project, this is redundancy, it should worked when use on main project only.
  • I don't like use command line, I use VS publish button.
  • How about .xml doc file?
  • I have the same issue as @ahdung. I want to exclude some massive XML docs from integrations with other services and only keep the API docs for Swashbuckle.

    I believe the real issue is that <Content Update="XXXX" CopyToPublishDirectory="Never" /> doesn't work for files generated by the buid process.

    See this:

        <ItemGroup>
            <Content Update="appsettings*.json" CopyToPublishDirectory="Never" />
            <Content Update="*.xml" CopyToPublishDirectory="Never" />
        </ItemGroup>

    If you put that in your *.pubxml file, only the appsettings*.json files wil be excluded.
    As far as I'm concerned that is a bug because at the time of publishing there should be no difference in how you treat files in the build output folder.

    The problem with the solution above is it's always excluded. But I need it excluded only for release builds. This works:

    <PropertyGroup Condition="'$(Configuration)'=='Release'">
      <DebugSymbols>False</DebugSymbols>
      <DebugType>None</DebugType>
    </PropertyGroup>

    Also interested in this feature for NativeAOT scenarios. Right now with a minimal api app the app is 25MB and the symbols 80MB (using StripSymbols on Linux). It's not obvious that you can get rid of the .dbg file if you care about the size (for most users I'd say). I would expect that these arguments would work on dotnet publish at least, and globally. Right now the .dbg file is still generated with these two arguments.

    @sebastienros I think there might be two separate scenarios here, actually.

  • Produce no symbols at all, anywhere.
  • Don't produce symbols during publish, but do produce them for build.
  • I think (1) can be a Native AOT specific issue that we should respect <DebugSymbols>false</> and <DebugType>none</>. (2) is the new scenario as it would only affect publish scenarios.

    Broadly though, I don't see how this would help the goal of informing users that they don't need to carry around the .dbg file. This seems like basically the same UX as .pdb files and I think the current expectation is that users know that they don't need to copy the PDB file around.

    adding the following PropertyGroup to the .pubxml seems to have solved the issue for me:

      <PropertyGroup>
        <DebugType>none</DebugType>
        <GenerateDocumentationFile>false</GenerateDocumentationFile>
        <AllowedReferenceRelatedFileExtensions>none</AllowedReferenceRelatedFileExtensions>
        <NoWarn>$(NoWarn);SA0001</NoWarn>
      </PropertyGroup>
    

    Update [2023-08-21]: Setting these properties within .pubxml only works when performing publish from within Visual Studio. For command line dotnet publish, DebugType needs to be specified as command line parameter to take effect:

    dotnet publish -p DebugType=none

    Since this was filed, the publish is down to a minimum set (exe, dll, runtimeconfig, deps, and pdb). pdb can be disabled with DebugType. Marking fixed. PublishDocumentationFile can also be used to disable publish for that particular file.
    https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#publishdocumentationfile

    Vì điều này đã được gửi, xuất bản được giảm xuống mức tối thiểu (exe, dll, runtimeconfig, deps và pdb). pdb có thể bị tắt bằng DebugType. Đánh dấu cố định. PublishDocumentationFile cũng có thể được sử dụng để tắt xuất bản cho tệp cụ thể đó. https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#publishdocumentationfile

    if i use
    p:DebugType=None it will cannot build native aot

    In my team we do store PDB files to symbol server. So I want to generate PDBs. At the same time we want to create Docker container with the application files, and this container must not contain PDB's (for security and size concerns). Nobody here demonstrated how that can be done AFAU.

    You may also specify the following properties, for PDB files to be included in extra symbols package (.snupkg):

    <PropertyGroup>
      <IncludeSymbols>true</IncludeSymbols>
      <SymbolPackageFormat>snupkg</SymbolPackageFormat>
    </PropertyGroup>

    See https://learn.microsoft.com/en-us/nuget/create-packages/symbol-packages-snupkg for more info.

    In my team we do store PDB files to symbol server. So I want to generate PDBs. At the same time we want to create Docker container with the application files, and this container must not contain PDB's (for security and size concerns). Nobody here demonstrated how that can be done AFAU.

    You may also specify the following properties, for PDB files to be included in extra symbols package (.snupkg):

    <PropertyGroup>
      <IncludeSymbols>true</IncludeSymbols>
      <SymbolPackageFormat>snupkg</SymbolPackageFormat>
    </PropertyGroup>
    

    See https://learn.microsoft.com/en-us/nuget/create-packages/symbol-packages-snupkg for more info.

    May be we do something wrong, but we build a Linux executable and put the content of publish folder into Docker container. This publish folder seems to always contain the PDBs if we generated them. Sure I can delete *.pdb afterwards when building the conainer. But more reasonable option would be to have an option to skip copying them.

    May be we do something wrong, but we build a Linux executable and put the content of publish folder into Docker container. This publish folder seems to always contain the PDBs if we generated them. Sure I can delete *.pdb afterwards when building the conainer. But more reasonable option would be to have an option to skip copying them.

    Thanks for clarifying. In this case you might want to specify DebugType=none as a command line argument when performing dotnet publish as a separate build step:

    dotnet publish -p DebugType=none

    Was there a problem with the ExcludeFoldersFromDeployment and ExcludeFilesFromDeployment in .pubxml files?
    I think this issue began because those are not supported by dotnet publish.
    Maybe bringing those back would make this issue go away.

    May be we do something wrong, but we build a Linux executable and put the content of publish folder into Docker container. This publish folder seems to always contain the PDBs if we generated them. Sure I can delete *.pdb afterwards when building the conainer. But more reasonable option would be to have an option to skip copying them.

    Thanks for clarifying. In this case you might want to specify DebugType=none as a command line argument when performing dotnet publish as a separate build step:

    dotnet publish -p DebugType=none

    Thanks for the tip. With this option, some PDBs are gone. But some are still left. Interesting.

    Actually it seems that only the PDBs of the project I am publishing are skipped. But this project has many project dependencies. And pdbs from those other projects are just copied over for whatever mysterious reason.

    Was there a problem with the ExcludeFoldersFromDeployment and ExcludeFilesFromDeployment in .pubxml files? I think this issue began because those are not supported by dotnet publish. Maybe bringing those back would make this issue go away.

    It seems similar as above. Only PDBs from the project being published are skipped. PDBs from dependent projects are copied over.

    IMO this issue should be re-opened. There is no way to skip copying PDB files into publish folder once they were generated. The only thing that worked for me was to delete them once they were copied, using .pubxml file:

      <Target Name="DeleteFiles" AfterTargets="Publish">
        <ItemGroup>
            <FilesToDelete Include="$(PublishDir)*.pdb"/>
        </ItemGroup>
        <Delete Files="@(FilesToDelete)">
        <Output
            TaskParameter="DeletedFiles"
            ItemName="FilesDeleted"/>
        </Delete>
        <Message Text="Deleted PDB files: @(FilesDeleted)" Importance="high" />
    </Target>
              

    To clarify final bit: we build everything in one step. And invoke dotnet publish with --no-build argument only to publish things that have been already built in another step. And for this reason none of the solutions suggested here work. Except for the last one suggested by me: let dotnet copy all that crap, and delete it afterwards.

    I want to point at the inconsistency of how the parameters applied: I tried to specify

    <DebugType>None</DebugType>
    <DebugSymbols>False</DebugSymbols>
    

    In my \PublishProfiles\FolderProfile.pubxml, it works only for the project you publish, not for references. I tried to do as @ducalai suggested - added publish parameters /p:DebugType=None /p:DebugSymbols=false and it worked for references too. BTW the same thing with -p:Configuration=Release

    When I try this and I but this two lines in my .pubxml file I get this error:

    https://stackoverflow.com/questions/77071059/the-debug-type-specified-in-the-dependency-context-could-be-parsed-asp-core-er/77071060#77071060

    Triage: @richaverma1 can you have your team set up a repro of this and provide a binlog? It should be a project that depends on another project and sets -p:DebugType=None -p:DebugSymbols=false during the publish but the dependent are still being picked up.

    It's not about debug symbols but other files that might be included in the project but we don't want to deploy. appsettings.json is a main example of that. web.config for web apis.

    The point is we can do that with .NET Framework projects but not with .NET ones because publication using .pubxml files doesn't support it.

    So the options provided correctly remove the pdbs but there is a desire for a solution for other files as well? We'll sync in triage next week on this. From our vendor testing, setting those properties in individual project files affects only those projects but setting it on the command line as suggested, does affect all projects which matches AGlezB commented.

    So the options provided correctly remove the pdbs but there is a desire for a solution for other files as well? We'll sync in triage next week on this. From our vendor testing, setting those properties in individual project files affects only those projects but setting it on the command line as suggested, does affect all projects which matches AGlezB commented.

    To be clear the main issue for me is that .pubxml has a syntax to specify files to exclude but in on only works for certain files. Here is an extract from a publish profile from one of our Web Api projects:

      <!-- Esto es para que no incluya archivos innecesarios al publicar -->
      <ItemGroup>
        <Content Update="appsettings*.json" CopyToPublishDirectory="Never" />
            Esto no funciona todavía con .NET Core
            https://github.com/dotnet/sdk/issues/16975
            <Content Update="*.xml" CopyToPublishDirectory="Never" />
            <Content Update="*.pdb" CopyToPublishDirectory="Never" />
            <Content Update="PrecisionApi.xml" CopyToPublishDirectory="PreserveNewest" />
      </ItemGroup>

    The translation for the comments is:

      <!-- To exclude unnecesary files on publish -->
      <ItemGroup>
        <!-- This isn't working on .NET Core yet -->
      </ItemGroup>

    The meaning of the settings is: we don't want any appsettings*.json or .xml (dll documentation) or .pdb files but we do want the PrecisionApi.xml file because that one populates the Swagger UI documentation.

    Of those the only one that works is the appsettings*.json one because the file are already included in the project. The other files are generated by the build process and the publish process doesn't recognize them which is why those are commented out and I'm keeping an eye on this issue.

    Ideally all four would work, which is to say I'd like to be able to write the rules in the .pubxml, commit the file to source control and forget about it. Command line is convenient but it's secondary to making the publish profile work.

    We investigated a bit and think you will need a custom target to accomplish this in a consistent manner. The reason for this is that your pubxml file is being read during project evaluation, but many of the items you want to customize are only available during build execution - they are created during the build. By definition, you must use targets to interact with these kinds of items.

    I think a good place to start investigating would be the DefaultCopyToPublishDirectoryMetadata target - this target in the SDK is responsible for defining how the Content/etc items are marked for copying to publish directories. If you create a target that has BeforeTargets="DefaultCopyToPublishDirectoryMetadata" then you should be able to detect any of the PDBs and other files you want to remove and set their metadata to not be copied.

    You can investigate your builds in detail using the MSBuild Structured Log Viewer tool.