dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

AfterTargets only works for first one in list #12675

Open asteiger opened 4 years ago

asteiger commented 4 years ago

I have a SPA build setup that will compile front end code differently based on the build configuration. This lets me do

dotnet publish -o publish -c Test dotnet publish -o publish -c Stage dotnet publish -o publish -c Release

for my CI pipeline and have it pull in proper runtime configs for specific environments.

However with my csproj file containing the following:

`

</Target>

<Target Name="PublishRunWebpackTest" AfterTargets="PublishUpdateModules" Condition=" '$(Configuration)' == 'Test' ">
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn build:test" />
</Target>

<Target Name="PublishRunWebpackStage" AfterTargets="PublishUpdateModules" Condition=" '$(Configuration)' == 'Stage' ">
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn build:stage" />
</Target>

<Target Name="PublishRunWebpackRelease" AfterTargets="PublishUpdateModules" Condition=" '$(Configuration)' == 'Release' ">
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn build:prod" />
</Target>

<Target Name="PublishCopyDist" AfterTargets="PublishRunWebpackTest;PublishRunWebpackStage;PublishRunWebpackRelease">
    <ItemGroup>
        <DistFiles Include="$(SpaRoot)dist\**" />
        <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
            <RelativePath>%(DistFiles.Identity)</RelativePath>
            <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
            <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
        </ResolvedFileToPublish>
    </ItemGroup>
</Target>`

The PublishCopyDist target only runs for the Test configuration, not Stage or Release. The individual PublishRunWebpack targets run properly according to configuration.

joeloff commented 4 years ago

Hi

For the copy PublishCopyDist, have you tried changing to DependsOnTargets (instead of AfterTargets)?