Skip to content

Commit debf971

Browse files
authored
archives.targets: Fix creating tar.gz on Windows (#15913)
1 parent f78c1dd commit debf971

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Microsoft.DotNet.Build.Tasks.Archives/build/archives.targets

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@
9191
DependsOnTargets="_CheckPigzAvailability"
9292
Condition="'$(SkipArchivesBuild)' != 'true'">
9393
<PropertyGroup>
94-
<_OutputPathRoot>$(IntermediateOutputPath)output/</_OutputPathRoot>
94+
<_OutputPathRoot>$([MSBuild]::NormalizePath($(IntermediateOutputPath), 'output'))</_OutputPathRoot>
9595
<_ArchiveFileName>$(ArchiveName)-$(Version)</_ArchiveFileName>
9696
<_ArchiveFileName Condition="'$(RuntimeIdentifier)' != ''">$(ArchiveName)-$(Version)-$(RuntimeIdentifier)</_ArchiveFileName>
97-
<_DestinationFileName>$(PackageOutputPath)/$(_ArchiveFileName).$(ArchiveFormat)</_DestinationFileName>
97+
<_DestinationFileName>$([MSBuild]::NormalizePath($(PackageOutputPath), '$(_ArchiveFileName).$(ArchiveFormat)'))</_DestinationFileName>
9898
</PropertyGroup>
9999
<MSBuild Projects="$(MSBuildProjectFullPath)"
100100
Targets="PublishToDisk"
@@ -106,14 +106,16 @@
106106
DestinationFile="$(_DestinationFileName)"
107107
Condition="'$(ArchiveFormat)' == 'zip'"/>
108108
<!-- use parallel gzip implementation when available -->
109-
<Exec Command="tar -C '$(_OutputPathRoot)' -cf - . | pigz &gt; '$(_DestinationFileName)'"
109+
<Exec Command="tar -cf - . | pigz &gt; '$(_DestinationFileName)'"
110110
IgnoreExitCode="true"
111111
IgnoreStandardErrorWarningFormat="true"
112+
WorkingDirectory="$(_OutputPathRoot)"
112113
Condition="'$(ArchiveFormat)' == 'tar.gz' and '$(_PigzFoundExitCode)' == '0'"/>
113114
<!-- otherwise, use built-in gzip feature (-z) -->
114-
<Exec Command="tar -C '$(_OutputPathRoot)' -czf '$(_DestinationFileName)' ."
115+
<Exec Command="tar -czf '$(_DestinationFileName)' ."
115116
IgnoreExitCode="true"
116117
IgnoreStandardErrorWarningFormat="true"
118+
WorkingDirectory="$(_OutputPathRoot)"
117119
Condition="'$(ArchiveFormat)' == 'tar.gz' and '$(_PigzFoundExitCode)' != '0'"/>
118120

119121
<Message Text="Successfully created archive -> '$(_DestinationFileName)' from '$(_OutputPathRoot)'" Importance="high" />
@@ -123,10 +125,10 @@
123125
DependsOnTargets="_CheckPigzAvailability"
124126
Condition="'$(CreateSymbolsArchive)' == 'true' and '$(SkipArchivesBuild)' != 'true'">
125127
<PropertyGroup>
126-
<_SymbolsOutputPathRoot>$(IntermediateOutputPath)symbols/</_SymbolsOutputPathRoot>
128+
<_SymbolsOutputPathRoot>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'symbols'))</_SymbolsOutputPathRoot>
127129
<_ArchiveFileName>$(SymbolsArchiveName)-$(Version)</_ArchiveFileName>
128130
<_ArchiveFileName Condition="'$(RuntimeIdentifier)' != ''">$(SymbolsArchiveName)-$(RuntimeIdentifier)-$(Version)</_ArchiveFileName>
129-
<_DestinationFileName>$(PackageOutputPath)/$(_ArchiveFileName).$(ArchiveFormat)</_DestinationFileName>
131+
<_DestinationFileName>$([MSBuild]::NormalizePath($(PackageOutputPath), '$(_ArchiveFileName).$(ArchiveFormat)'))</_DestinationFileName>
130132
</PropertyGroup>
131133
<MSBuild Projects="$(MSBuildProjectFullPath)"
132134
Targets="PublishSymbolsToDisk"
@@ -138,14 +140,16 @@
138140
DestinationFile="$(_DestinationFileName)"
139141
Condition="'$(ArchiveFormat)' == 'zip'"/>
140142
<!-- use parallel gzip implementation when available -->
141-
<Exec Command="tar -C '$(_OutputPathRoot)' -cf - . | pigz &gt; '$(_DestinationFileName)'"
143+
<Exec Command="tar -cf - . | pigz &gt; '$(_DestinationFileName)'"
142144
IgnoreExitCode="true"
143145
IgnoreStandardErrorWarningFormat="true"
146+
WorkingDirectory="$(_SymbolsOutputPathRoot)"
144147
Condition="'$(ArchiveFormat)' == 'tar.gz' and '$(_PigzFoundExitCode)' == '0'"/>
145148
<!-- otherwise, use built-in gzip feature (-z) -->
146-
<Exec Command="tar -C '$(_OutputPathRoot)' -czf '$(_DestinationFileName)' ."
149+
<Exec Command="tar -czf '$(_DestinationFileName)' ."
147150
IgnoreExitCode="true"
148151
IgnoreStandardErrorWarningFormat="true"
152+
WorkingDirectory="$(_SymbolsOutputPathRoot)"
149153
Condition="'$(ArchiveFormat)' == 'tar.gz' and '$(_PigzFoundExitCode)' != '0'"/>
150154

151155
<Message Text="Successfully created archive -> '$(_DestinationFileName)' from '$(_SymbolsOutputPathRoot)'" Importance="high" />

0 commit comments

Comments
 (0)