I have setup a python project in Visual Studio 2017 Enterprise (Version 15.4) as part of a mixed-project solution also containing various C#(.Net 4.6.2, .Net Core 2.0 and Xamarin) projects. During the build I want to generate several .py source code files using some self-written C# tool which is also part of the build. Additionally all .py files listed as "Compile" items in the .pyproj file should be compressed into a .zip file and written to some output directory.
In my .pyprof MSBuild file I craeated two "custom build step" targets like so:
<Target Name="MyPreBuildStep" BeforeTargets="Build">
Call self-written py-Code generator
</Target>
<Target Name="MyPostBuildStep" AfterTargets="Build"
Inputs="@(Compile)"
Outputs="$(OutputPath)\$(PythonProjectName).zip">
<Zip ZipFileName="$(OutputPath)\$(PythonProjectName).zip"
WorkingDirectory="$(MSBuildProjectDirectory)\..\" Files="@(Compile)" />
</Target>
The Zip Task being imported from the MSBuildCommunityTasks.
If I right-click on the project in Visual Studio and hit "Rebuild" everything works fine. The py-code is generated in advance and all @(Compile) items are put into the .zip file.
Unfortunately the normal "Build" NEVER invokes the above targets. So with my current setup, I can build my 40-projects containing solution just by hitting "Build" BUT the python projects needs an extra-invitation by hitting "Rebuild". Very annoying.
I tried to investigate the contents of "Microsoft.Python.Tools.Web.targets" and "Microsoft.Python.Tools.targets". Somewhere inside these files a comment says: "The Build target is invoked as part of the Publish phase." hmmm.
Can somebody tell me how to specify some simple custom build steps in a .pyproj that just work during a normal "Build"?
Thank you.