question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Post build variables empty when executing "Publish"

See original GitHub issue

Hi,

a working post build event is not working when publishing the project because $(SolutionDir) and $(TargetDir) are empty.

Project file:

<PropertyGroup>
  <TargetFramework>net462</TargetFramework>
  <PreserveCompilationContext>true</PreserveCompilationContext>
  <AssemblyName>XXX</AssemblyName>
  <OutputType>Exe</OutputType>
  <PackageId>XXX</PackageId>
  <UserSecretsId>XYZ</UserSecretsId>
  <RuntimeIdentifiers>win8-x64</RuntimeIdentifiers>
  <PostBuildEvent>xcopy /D /Y "$(SolutionDir)src\ABC\*.*" $(TargetDir)</PostBuildEvent>
  <TypeScriptToolsVersion>2.5</TypeScriptToolsVersion>
</PropertyGroup>

Error:

The command "xcopy /D /Y "src\ABC\*.*" " exited with code 4.

Exception:

System.AggregateException: One or more errors occurred. ---> System.Exception: Publish failed due to build errors. Check the error list for more details.
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Web.Publish.PublishService.VsWebProjectPublish.<>c__DisplayClass40_0.<PublishAsync>b__2()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ApplicationCapabilities.Publish.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__108.MoveNext()
---> (Inner Exception #0) System.Exception: Publish failed due to build errors. Check the error list for more details.<---

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dasMullicommented, Feb 26, 2018

you could also do

<ItemGroup>
  <Content Include="..\src\ABC\**"
           CopyToOutputDirectory="PreserveNewest" 
           CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>

instead of the post build event. That way it even works cross-platform (xcopy is windows only)

1reaction
livarcocccommented, Feb 23, 2018

This is likely a dup of https://github.com/dotnet/sdk/issues/677.

Can you try replacing your post build event with a Target?

Also, below is a exert from https://github.com/Microsoft/msbuild/issues/2743

Do not depend on SolutionDir, or any other sln dependent property. SolutionDir is only set when you are building a solution. It has no meaning when building the csproj directly (or a dirs.proj sln replacement). Best to consider the sln file deprecated. Instead, place a directory.build.props at the root of your repo and define a root property like $(MSBuildThisFileDirectory)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pre- Post- Build Event Variables in Visual Studio are Empty
1 Answer. This happens because in . NET Core projects, the pre- and post build macros are set too early and the $(ProjectDir)...
Read more >
Pre-build Event/Post-build Event Command Line Dialog Box
Contains the events to run either for pre-build or post-build. Note. Add a call statement before all post-build commands that run .bat files....
Read more >
Publish Over SSH
If the Source files box is empty then no files will be transferred. Environment variables. Source files, Remove prefix, Remote directory and ...
Read more >
Untitled
Build.props files - Substack WebApr 1, 2021 · MSBuild has two variable types: ... 2018 Post build variables empty when executing "Publish" dotnet/sdk#1987 ......
Read more >
Configuring build settings - AWS Amplify Hosting
You can configure Amplify Hosting to use diff based backend builds using the AMPLIFY_DIFF_BACKEND environment variable. When you enable diff based backend ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found