Visual Studio 2017 macros show empty on build but not in macro selector
Asked Answered
V

2

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

Vani answered 14/3, 2017 at 4:2 Comment(0)
P
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

Paramorphism answered 23/3, 2017 at 18:35 Comment(2)
I've created a project that demonstrates the issue: github.com/BalassaMarton/VS2017Issues/tree/master/…Belie
circa 2021: the issue still thereEnsoul
U
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">
Undersigned answered 24/7, 2019 at 11:44 Comment(2)
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.Cussed
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.Cussed

© 2022 - 2024 — McMap. All rights reserved.