Micha
Micha

Reputation: 151

MSBuild ZipDirectory Task uses backslash on some computer but forward slash on another

I have the following as part of a "Deploy" project which I run manually from a batch file using msbuild.exe (VS2017).

<Target Name="ZipRelease"
    DependsOnTargets="getversion;gettime">
<MakeDir Directories="$(ReleaseDir)" Condition="!Exists('$(ReleaseDir)')" />
<ZipDirectory Condition="Exists('$(BuildDir)')"
    SourceDirectory="$(BuildDir)"
    DestinationFile="$(ReleaseDir)\$(MODNAME)-$(DLLVersion)_$(CurrentDate).zip" />
</Target>

On one PC I use the Community Edition of VS2017. I may also have installed VS2019 on that machine (no way to check for a couple of weeks). Crucially the batch file forces the use of VS2017. On another PC I have VS2017 Professional.

On the PC using the Community Edition, this task creates correct zip files which use forward-slashes as the path separator. On the PC using VS2017Pro, the task creates zip files with back-slashes which is obviously against the spec and causes lots of problems (the resulting ZIP is deployed on Linux as well as Windows).

This thread indicates DotNet 4.6.1 or later fixes the path separator used when creating ZIP files. I specify ToolsVersion="15.8" as part of the Project configuration (minimum version for the ZipDirectory task), but how do I force the DotNet version for an MSBuild Task?

I've tried uninstalling all earlier versions of Dotnet SDK/target framework from the PC to no avail.

There's also an override documented (Switch.System.IO.Compression.ZipFile.UseBackslash), but that only applies to applications, not MSBuild Tasks.

As seems usual with MS stuff, there's inconsistencies everywhere and my Google skills are insufficient to find an answer so grateful for anybody being able to point me in the right direction.

Upvotes: 0

Views: 524

Answers (2)

Micha
Micha

Reputation: 151

Installing VS2019 fixes it.

It seems my script automatically configures itself to use the newest version of Visual Studio instead of forcing itself to VS2017 as I had originally stated.

Even though all DotNet version numbers as reported by the build script for its runtime framework are still the same, something is obviously different between running in a VS2017 vs VS2019 environment.

It would be very very nice to figure out exactly what and whether it's possible to force the VS2017 intall to use that as well..

Upvotes: 1

Mr Qian
Mr Qian

Reputation: 23848

Try to use

<ZipDirectory Condition="Exists('$(BuildDir)')"
    SourceDirectory="$(BuildDir)"
    DestinationFile="$([System.String]::Copy($(ReleaseDir)\$(MODNAME)-$(DLLVersion)_$(CurrentDate).zip).Replace('\', '/'))" />

Actually, all my agents are using back-slashes for path. And windows always uses back-slashes for path, so I wonder if you have made some changes to your windows or VS IDE to use forward-slashes for that PC.

Linux uses forward-slashes but Windows do not use that by default.

You can open the folder of the C disk to check whether the path uses forward-slashes. And make sure whether you have run some cmd commands to use that.

Open VS IDE, compare with the two versions from the two PCs, open Extensions-->Manage Extensions-->Installed to check whether you have installed some extensions to cause that.

Upvotes: 0

Related Questions