This project has moved and is read-only. For the latest updates, please go here.

adding build steps using PythonVS 2.1 alpha

Mar 27, 2014 at 4:40 PM
Edited Mar 27, 2014 at 7:48 PM

I'm reading the new version 2.1 supports adding build steps manually to the projet file. Is there any examples of this I could refer to?

Mar 28, 2014 at 6:34 PM
The MSBuild documentation is pretty good, and it's going to be accurate information. Basically, right now you'll need to open the .pyproj file directly (VS will let you Unload Project and then Edit Project File, or you can use Notepad/equivalent) and edit it that way.

There is one trick with Python projects, which is enabling the Build step in VS. You'll notice that Web projects can be built, but non-web projects can't. This is deliberate, because it saves time for people who don't ever need to build. If your Build menu is empty, you'll need to add the following code to your project (or a .targets file, if you're importing another one of those):
<Target Name="CoreCompile" />
<Target Name="CreateManifestResourceNames" />
These can go anywhere within the top-level Project element. You may also need to modify your solution configuration (Build menu -> Configuration Manager) because VS may not have set the checkbox for your project to build. Once you've done this, your project should build every time you hit F5.

Let us know if you have any more questions. Eventually we will document this area more formally, but right now we're interested to find out exactly what needs documenting.
May 6, 2014 at 5:25 PM
Hi Zooba,

I just wanted to give an update.

I finally managed to get this thing to work but I'm not really happy with it...

The CoreCompile Target enables the project in the Configuration Manager to activate the build.

Since the CoreCompile is actually trying to compile its expecting an temp output as a result which in my case never actually occur so I had to fake it like this.
  <Target Name="CoreCompile">
    <Exec Command="echo test > $(TargetDir)obj\$(Configuration)\$(TargetName).exe"/>
This removed the error of compile it was always raising.

I added a second Exec task to trigger my build event.
  <Target Name="CoreCompile">
    <Exec Command="$(SolutionDir)/_scripts/postbuildcopy_MobuG2.bat $(Configuration)"/>
    <Exec Command="echo test > $(TargetDir)obj\$(Configuration)\$(TargetName).exe"/>
Both tasks run before the CoreCompile so the order is pretty irrelevant.


I hope this can help anyone else. If you know a way to tell the CoreCompile to not expect any output please let me know :)

May 6, 2014 at 6:04 PM
I've just been working on much the same thing - there are a number of other things that need to be overridden to make it work nicely, but I think we can eventually roll most of those into our PythonTools.targets file.

I think we added the following code into the targets file between 2.1 Alpha and Beta. This may help with the extra command you needed:
  <!-- We don't have an intermediate assembly, but the common targets will set
       one anyway. We clear it before PrepareForBuild in case another targets
       file overrides that one.
  <Target Name="_ClearIntermediateAssembly" BeforeTargets="PrepareForBuild">
      <IntermediateAssembly Remove="@(IntermediateAssembly)" />

  <Target Name="PrepareForBuild">
    <MakeDir Directories="$(OutDir);@(CreateDirectory)" ContinueOnError="True"/>
I've also added the CreateManifestResourceNames target here, so by the time 2.1 RTM comes out you'll only need to add CoreCompile. We'll probably recommend adding that and then overriding BeforeBuild and AfterBuild, like in C# (in fact, while I'm thinking about this, I'll go and add them to the default template).

Thanks for the feedback. Keep it coming :)