Post build variables empty when executing "Publish"
See original GitHub issueHi,
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:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you could also do
instead of the post build event. That way it even works cross-platform (
xcopy
is windows only)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)