sdk
sdk copied to clipboard
dotnet publish - way to remove pdb and other files
Hi,
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
@livarcocc @jeffschwMSFT
Hi @scalablecory @livarcocc @jeffschwMSFT,
please let me know if there is a way to remove these unnecessary files during publish.
Same question with dotnet core 3.1 web application. Any way to remove those unrequired files using command line parameters or .csproj PropertyGroup properties? DebugType=None and DebugSymbols=false ~~seem to be ignored.~~
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.
@saxenark did the answer given by @ducalai solve your problem?
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 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.
Issue still here.
- I want
.pdbin release folder but not in publish. - I don't want use
DebugTypefor 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
.xmldoc 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>
@jeffschwMSFT any progress on this? As of net7.0 we still cannot exclude certain files.
@agocke should this issue be in SDK or runtime?
SDK. The proposal as stands is some sort of property to affect all publish scenarios, which is core SDK logic.
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.
Agreed. I want 2) here.
If you are experiencing all kinds of junk files in your publish output directory, it may be because you have set <PublishDir> and <PublishUrl> to the same value in your .pubxml profile. This apparent bug has been reported to Microsoft here.
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.
@dobsa You want to create a .snupkg using dotnet pack --include-symbols
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.
@dobsa You want to create a
.snupkgusingdotnet pack --include-symbols
I don't really mind how and where the symbols end up, as long as they are not present in the publish directory.
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
publishfolder into Docker container. Thispublishfolder seems to always contain the PDBs if we generated them. Sure I can delete*.pdbafterwards 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
publishfolder into Docker container. Thispublishfolder seems to always contain the PDBs if we generated them. Sure I can delete*.pdbafterwards 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 publishas 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
ExcludeFoldersFromDeploymentandExcludeFilesFromDeploymentin.pubxmlfiles? I think this issue began because those are not supported bydotnet 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>