dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

MSBuild with WebPublishMethod to package produces wrong file names with special characters in zip file #6165

Open asranja opened 3 years ago

asranja commented 3 years ago

I am using below MSBuild command to generate a package zip for a web application which contains files with Swedish characters. The generated zip corrupts the file name.

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" "C:\Users\asranja\Source\Repos\WebApplication4\WebApplication4.sln" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="C:\Users\asranja\Desktop\Package2"

[Solution]

packagezip1

[Unzipped package] packagezip2

[Ask] What is the correct way to generate a webapp zip package which does not corrupt file names with special characters.

benvillalobos commented 3 years ago

@dsplaisted is this an sdk issue?

dsplaisted commented 3 years ago

@BenVillalobos The issue might be in the .NET SDK, the publishing system, MSBuild, or something else.

@asranja Would it be possible for you to provide a repro project and/or a binlog of the build that does this?

asranja commented 3 years ago

Please use this for repro https://github.com/asranja/web-application. I just created an ASP.NET MVC application and added a file with Swedish characters in name.

sandrosuter commented 3 years ago

@asanjabi Have you found a solution yet? I have the same problem.

asanjabi commented 3 years ago

@asanjabi Have you found a solution yet? I have the same problem.

I think you meant to tag @asranja

benvillalobos commented 3 years ago

Investigation notes:

There are no garbled characters in the binlog anywhere. Also, looking into the obj/ folder, Pts.Master.Analys.Jämförelse.dll looks to be generated with a proper name. When the file is copied over to bin/ it also has the proper name.

Thinking this could be an issue with the publishing system. Where is this file copied over...

I think I've narrowed it down to the VSMSDeploy task. After a successful build using the repro steps, you can just run msbuild WebApplication4.sln /bl /t:PackageUsingManifest and see a generated zip file with the mangled name. It comes from Microsoft.Web.Publishing.targets, who owns that?

vijayrkn commented 3 years ago

@BenVillalobos - Can you please pass the property UseMsDeployExe to true and see what it outputs? If it is passing all the right parameters to msdeploy.exe, then it could be an issue in the msdeploy tool itself. Can you share the output after passing the UseMsDeployExe to true?

benvillalobos commented 3 years ago

@vijayrkn Running msbuild WebApplication4.sln /bl /t:PackageUsingManifest /p:UseMsDeployExe=true

This is the console output of the PackageUsingManifest target:

PackageUsingManifest:
  Packaging into C:\src\git\_customerProjects\web-application\WebApplication4\obj\Debug\Package\WebApp
  lication4.zip.
  Running msdeploy.exe.
  C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe -source:manifest='C:\src\git\_custom
  erProjects\web-application\WebApplication4\obj\Debug\Package\WebApplication4.SourceManifest.xml' -de
  st:package='C:\src\git\_customerProjects\web-application\WebApplication4\obj\Debug\Package\WebApplic
  ation4.zip',IncludeAcls='False' -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtensi
  on -disableLink:CertificateExtension -declareParamFile:"C:\src\git\_customerProjects\web-application
  \WebApplication4\obj\Debug\Package\WebApplication4.Package.Parameters.xml" -retryAttempts=2
  Info: Updating file (C:\src\git\_customerProjects\web-application\WebApplication4\obj\Debug\Package\
  PackageTmp\bin\WebApplication4.dll).
  Info: Updating file (C:\src\git\_customerProjects\web-application\WebApplication4\obj\Debug\Package\
  PackageTmp\bin\WebApplication4.pdb).
  Total changes: 2 (0 added, 0 deleted, 2 updated, 0 parameters changed, 29184 bytes copied)
  Successfully execute msdeploy.exe.
  Package "WebApplication4.zip" is successfully created as single file at the following location:
  file:///C:/src/git/_customerProjects/web-application/WebApplication4/obj/Debug/Package
  To get the instructions on how to deploy the web package please visit the following link:
  https://go.microsoft.com/fwlink/?LinkId=124618

The dll in the zip folder is still borked: Pts.Master.Analys.Jämförelse.dll

Edit: Same resulting dll name if I delete the previous zip and run again.

vijayrkn commented 3 years ago

Looks like all the params to msdeploy.exe seems correct, do you see anything wrong in the any of the xmls passed to it? If not, this will have to go to the msdeploy team C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe -source:manifest='C:\src\git\_custom erProjects\web-application\WebApplication4\obj\Debug\Package\WebApplication4.SourceManifest.xml' -de st:package='C:\src\git\_customerProjects\web-application\WebApplication4\obj\Debug\Package\WebApplic ation4.zip',IncludeAcls='False' -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtensi on -disableLink:CertificateExtension -declareParamFile:"C:\src\git\_customerProjects\web-application \WebApplication4\obj\Debug\Package\WebApplication4.Package.Parameters.xml" -retryAttempts=2

benvillalobos commented 3 years ago

Looks normal to me:

WebApplication4.SourceManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<parameters>
  <parameter name="IIS Web Application Name" description="" defaultValue="Default Web Site/WebApplication4_deploy" tags="IisApp">
    <parameterEntry kind="ProviderPath" scope="IisApp" match="^C:\\src\\git\\_customerProjects\\web-application\\WebApplication4\\obj\\Debug\\Package\\PackageTmp$" />
    <parameterEntry kind="ProviderPath" scope="setAcl" match="^C:\\src\\git\\_customerProjects\\web-application\\WebApplication4\\obj\\Debug\\Package\\PackageTmp$" />
  </parameter>
</parameters>
vijayrkn commented 3 years ago

@ning51 - Do you know if this is a known MSDeploy issue?

phishyYy commented 2 years ago

Any solution to this issue? Seems the thread died about a year ago without a solution.

sandrosuter commented 2 years ago

I also had this problem in the past and then searched for a long time what is wrong here. I then found out that there is also a coding for Zip File.

Especially with Powershell it did this differently than when I created it with via the GUI. I then found the following zip command that works for me today.

`Add-Type -Assembly 'System.IO.Compression.FileSystem' $enc = [System.Text.Encoding]::GetEncoding(29001) #29001, x-Europa, Europa

[System.IO.Compression.ZipFile]::ExtractToDirectory($packageZipPath, $unzipPath, $enc)`

OronDF343 commented 1 year ago

I have tested and found that it is not related to the system locale. If I use the method by @sandrosuter I can get the correct file names if I pass Encoding.UTF8. So I can fix the file like this:

using System.IO;
using System.IO.Compression;
using System.Text;

var fs = new FileStream("publish/package.zip", FileMode.Open);
var z = new ZipArchive(fs, ZipArchiveMode.Update, false, Encoding.UTF8);
z.Dispose();

(Remember to add reference to System.IO.Compression.FileSystem)