Search code examples
.net-coremsbuildcsprojmsbuild-propertygrouppublishdir

MSBuild .NET Core 3.1 application - Set PublishDir value in csproj


I struggle to set the PublishDir value in the new .net core 3.1 csproj format. In the old csproj format I was able to set the value like this:

<PropertyGroup>
<PublishDir>..\test\path</PublishDir>

I was even able to use a Condition attribute in the PublishDir element to use different values depending on the build configuration.

Now with the new csproj I tried the same, but the PublishDir is still set to something like: bin/Release/netcoreapp3.1/win-x64/app.publish. Where does this directory come from?

Only when I add the parameter via msbuild call with /p:PublishDir="..\test\path" the application gets published in the appropriate directory.

Is there anything else I need to take into consideration? Do I need to set the value after a specific target, like PrepareForPublish?


Solution

  • This is the solution I had mentioned in the comment before:

    <Target Name="CustomPublishTarget" BeforeTargets="PrepareForPublish">
      <ItemGroup>
          <PublishDir Include="$(PublishDir)" />
      </ItemGroup>
    
      <PropertyGroup>
          <PublishDir>..\test\path</PublishDir>
      </PropertyGroup>
    </Target>