Skip to content

$(TargetPath) or $(TargetDir) are empty on PostBuild event on netstandard project #1055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
marcusien opened this issue Mar 30, 2017 · 10 comments

Comments

@marcusien
Copy link

Hi,

There's an issue with post build event on netstandard library.
when executing a post build event, the $(TargetDir) et $(TargetPath) macros are empty while they are not empty on the "post build event command line" wizard on visual studio.

You can reproduce it easily by

creating a netstandard project library
put an echo "Target path is : " $(TargetPath)"
then build the project
take a look at output window
This works for $(SolutionDir) or other macros

@ripenko
Copy link

ripenko commented Apr 5, 2017

ProjectDir, OutDir, ProjectName don't work also

@nivinj
Copy link

nivinj commented Apr 5, 2017

Also ConfigurationName

@dsplaisted
Copy link
Member

We will probably be disabling pre and post build events and recommend people use targets instead. For example:

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="echo Before Build: $(OutDir)" />
  </Target>

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="echo After Build: $(OutDir)" />
  </Target>

Closing this issue as a duplicate of #677. See also dotnet/project-system#1569 which is for updating the property pages in VS.

azabluda added a commit to azabluda/InfoCarrier.Core that referenced this issue Apr 28, 2017
Use PreBuild task / command-line GitVersion as a workaround (Windows only) dotnet/sdk#1055 (comment)
Don't generate .nupkg on build
@QuantumHive
Copy link

Where can we find these recommendations? I had to find it out the hard way after banging my head for hours why the events didn't work.

mmitche pushed a commit to mmitche/sdk that referenced this issue Jun 5, 2020
…0191030.2 (dotnet#1055)

- Microsoft.AspNetCore.Analyzers - 5.0.0-alpha1.19530.2
- Microsoft.AspNetCore.Mvc.Api.Analyzers - 5.0.0-alpha1.19530.2
- Microsoft.AspNetCore.Mvc.Analyzers - 5.0.0-alpha1.19530.2
- Microsoft.AspNetCore.Components.Analyzers - 5.0.0-alpha1.19530.2
@CaledoniaProject
Copy link

This saved my day. The easiest solution is to remove <PostBuildEvent> in the csproj file then recreate the script in Visual Studio.

@icnocop
Copy link

icnocop commented Nov 25, 2020

Related: dotnet/try-convert#269

@paul-datatech911
Copy link

This saved my day. The easiest solution is to remove <PostBuildEvent> in the csproj file then recreate the script in Visual Studio.

What do you mean by this @CaledoniaProject ? We have PostBuild events that use signtool.exe to sign assemblies from .NetFramework projects that were then run through the upgrade-assistant for VS2022/net6 targeting. Those no longer work presumably because many of the macros we use no longer exist in the SDK-style projects and/or VS2022.

"C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool.exe" sign /f "G:\codesign.pfx" /p ****** /tr "http://timestamp.sectigo.com" /td sha256 /fd sha256 ""

What does "recreate the script in Visual Studio" mean exactly?

@SirBogman
Copy link

What does "recreate the script in Visual Studio" mean exactly?

It means to go to the project properties page, go to the build/events section, then paste in your pre-build and post-build events.

It will create new targets for you like the following, as long as you delete the old <PostBuildEvent> and <PreBuildEvent> first.

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="echo Before Build: $(OutDir)" />
  </Target>

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="echo After Build: $(OutDir)" />
  </Target>

@krypt-lynx
Copy link

krypt-lynx commented Nov 6, 2022

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="echo &quot;pre-build&quot;&#xD;&#xA;&#xD;&#xA;git describe --tag --dirty --always &gt; &quot;$(ProjectDir)\git.txt&quot;&#xD;&#xA;&#xD;&#xA;cd &quot;$(TargetDir)&quot;&#xD;&#xA;&#xD;&#xA;echo &quot;target dir:&quot;&#xD;&#xA;echo &quot;$(TargetDir)&quot;&#xD;&#xA;echo &quot;current dir:&quot;&#xD;&#xA;cd&#xD;&#xA;&#xD;&#xA;del /Q *.*" />
  </Target>

I have this...
I editing my projects by hand and this is utterly unreadable.

@KalleOlaviNiemitalo
Copy link
Contributor

@krypt-lynx would a PropertyGroup with a CDATA section work?

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <PropertyGroup>
      <PreBuildCommands><![CDATA[echo "pre-build"

git describe --tag --dirty --always > "$(ProjectDir)\git.txt"

cd "$(TargetDir)"

echo "target dir:"
echo "$(TargetDir)"
echo "current dir:"
cd

del /Q *.*]]></PreBuildCommands>
    </PropertyGroup>
    <Exec Command="$(PreBuildCommands)" />
  </Target>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests