Not sure if it's better approach for you, here're two directions which may help:
1.Nuget way: Include your powershell script as content files when creating the nuget package, then when you build the project, the script will be copied to output path automatically. So you can specify the post-build event with macro $(OutputPath)
. Anyone interested in it can check blog here.
For your .net core
project which uses PackageReference, use the ContentFiles element. There's many topics about how to create the package with content files using ContentFiles
element online, so I won't talk details here, but if you want to choose this way and meet some issues, let me know that :)
2.MSBuild way: Using something like Directory.Build.props to customize your build. Since your original problem is to share postbuild Powershell Script in multiple solution
, let's place the script test.ps1
in path C:\PostBuildScript\
, let's create a .txt file with content below, and then rename it to Directory.Build.props
:
<Project>
<PropertyGroup>
<ScriptPath>C:\xxx\xxx\</ScriptPath>
</PropertyGroup>
</Project>
Now if we place this file in Solution-A's directory, all projects in A solution can recognize $(ScriptPath)
, so we can use parameter like $(ScriptPath)test.ps1
in build event. If you meet code9009 when calling PS script in build event, see here.
And if those solutions are under folder TestFolder
, place the Directory.Build.props
file in that folder, it will work for all solutions in that folder. Also, there's many directions to customize your post-build events, it depends on your needs...