Visual Studio 2017 macros appear blank during assembly, but not in the macro selector

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 assembly starts the value, empty is displayed.

the following was created using echo: "Project path:" $ (ProjectPath) "end of path"

build output

any macro value i use seems to be 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 tried manually editing csproj to no avail. the full path to csproj in the post build event does not work.

I confirmed that this happens on multiple machines with VS / 15.0.0 + 26228.9

+7
source share
2 answers

There seems to be a bug with ignored macro variables like $(ConfigurationName) , at least in Visual Studio 2017 ver. 9/15/11

This worked for me:
Specify your script in the <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"> 
0
source

Source: https://habr.com/ru/post/1265414/


All Articles