Skip to content

Post build variables empty when executing "Publish" #1987

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

Open
ManuelHaas opened this issue Feb 23, 2018 · 5 comments
Open

Post build variables empty when executing "Publish" #1987

ManuelHaas opened this issue Feb 23, 2018 · 5 comments
Milestone

Comments

@ManuelHaas
Copy link

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.<---
@livarcocc
Copy link
Contributor

livarcocc commented Feb 23, 2018

This is likely a dup of #677.

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

Also, below is a exert from dotnet/msbuild#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)

@livarcocc livarcocc added this to the Discussion milestone Feb 23, 2018
@ManuelHaas
Copy link
Author

I don't know it its a dup of #677. The error here occurs when publishing a solution. So publishing in conjunction with post build events with variables is not possible.
Replacing the post build event with a Target would work but is inpractical in team environment.

"Best to consider the sln file deprecated."

This is a joke, right? Is this the official position of Microsoft? If yes why are sln files still included in project templates?

@dasMulli
Copy link
Contributor

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)

@ManuelHaas
Copy link
Author

@dasMulli Thanks a lot! I didn't know about that. This solved it for me.

@soroshsabz
Copy link

ITNOA

How to find solution dir with new msbuild?

JL03-Yue pushed a commit that referenced this issue Mar 19, 2024
* Update dependencies from https://github.com/dotnet/runtime build 20231020.16

Microsoft.Extensions.FileSystemGlobbing , Microsoft.Extensions.Logging
 From Version 8.0.0-rtm.23517.16 -> To Version 8.0.0-rtm.23520.16

* Update dependencies from https://github.com/dotnet/runtime build 20231023.12

Microsoft.Bcl.AsyncInterfaces , Microsoft.Extensions.FileSystemGlobbing , Microsoft.Extensions.Logging
 From Version 8.0.0-rtm.23517.16 -> To Version 8.0.0

* Stabilize package version

* Remove package source mapping

* Update Version.Details.xml

* Update azure-pipelines-official.yml

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Jan Jones <[email protected]>
Co-authored-by: Viktor Hofer <[email protected]>
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

4 participants