9

When I add a post build event to my project and try to use a macro in the Edit Post-Build ... section it shows the value of each macro

post build events

However when the build runs the value show blank

the following was generated using echo "The project path is:" $(ProjectPath) "end of path"

build output

any macro value I use seems to come up null

I am using the following csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard1.6</TargetFramework>
    <AssemblyName>Client</AssemblyName>
    <PackageId>Client</PackageId>
    <PackageTags>pkgname</PackageTags>
    <NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
    <PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <PostBuildEvent>
      echo on
      echo "The project path is:" $(ProjectPath) "end of path"
      dotnet pack $(ProjectPath)
    </PostBuildEvent>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="NoSQL" Version="1.0.4.3" />
  </ItemGroup>

</Project>

I have tried manually editing the csproj to no avail. a full path to the csproj in the post build event does work.

I have confirmed that this occurs on multiple machines running VS/15.0.0+26228.9

Vinez
  • 560
  • 2
  • 11

2 Answers2

5

This is an open issue for VS 2017 https://developercommunity.visualstudio.com/content/problem/25206/build-events-window-strips-out-macros-unce-saved.html

Márton Balassa
  • 818
  • 7
  • 11
1

There seem to be a bug with the macro environment variables like $(ConfigurationName) being ignored, at least in Visual Studio 2017 ver. 15.9.11

This worked for me:
Specify your script in a <Target Name=...> element in the project file (.vbproj)

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        ...
        ...
    </PropertyGroup>

    <Target Name="PostBuild" BeforeTargets="PostBuildEvent">
        <!-- For " use &quot; -->
        <Exec Command="
            if $(ConfigurationName) == Debug (
                echo Upload Debug files:
                cmd /c &quot;S:\My Script\Debug_upload.cmd&quot;
            )
            if $(ConfigurationName) == Release (
                echo Upload Release files:
                cmd /c &quot;S:\My Script\Release_upload.cmd&quot;
            )"/>
    </Target>
    ...
<Project Sdk="Microsoft.NET.Sdk">
MrCalvin
  • 1,675
  • 1
  • 19
  • 27
  • This worked for me, though I needed to use Name="PreBuild" and BeforeTargets="PreBuildEvent" in order to get a command to run before the project is built. – Eric Mutta Mar 24 '20 at 00:09
  • I can also confirm that this is an issue in Visual Studio Community 2017 v15.8.5 but seems to have been fixed in Visual Studio 2019. – Eric Mutta Mar 24 '20 at 00:10