Skip to content

Instantly share code, notes, and snippets.

@freakboy3742
Last active April 13, 2017 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freakboy3742/469a9f7ccd5bbb79e6130bab95a375a6 to your computer and use it in GitHub Desktop.
Save freakboy3742/469a9f7ccd5bbb79e6130bab95a375a6 to your computer and use it in GitHub Desktop.
The challenge

The Challenge

Abstract

Develop a Visual Studio 2017 solution file that will enable a user to download a zip file of content (including a solution file), open the solution, hit run, and have the code Just Work (tm).

Full description

Python.net contains an example project that shows how to embed a Python interpreter into a C# project. However, this project doesn't work "out of the box" - it requires a bunch of configuration before it will work. It is part of a larger project, so you need to modify the solution file to set the starting project; then, when you do run it, you get errors because Python27.dll can't be found - which is problematic if you're trying to use Python 3.5.

I want to be able to give someone a zip file that contains the solution file and source code, have them open the file, run it, and get a useful executable.

The deliverable is the zip file, containing a Visual Studio 2017 solution file, the C# source code from the Python.net console demo, and any other support files necessary. I imagine this will include:

  • A copy of Python. The zip file should contain the official embedded python zip file in a known location relative to the solution file. However, you cannot depend on a system installation of Python (or anything else other than Visual Studio).
  • An installation of Python.net. Ideally, this will be in a directory other than the site-packages provided by the embedded Python install

When compiled, the executable should have a custom icon; any icon will do for sample purposes, but it should also be available in the zip file.

The ideal layout for the final zip file would be:

  • Windows
    • MyProject.sln
    • MyProject.cs
    • MyProject
      • Resources
        • myproject.ico
      • Python
        • (contents of embedded Python zip file)
      • app_packages
        • (installed version of python.net)
      • app
        • MyProject
          • __init__.py
          • app.py

The solution file should output "MyProject.exe" in the MyProject directory.

Bonus points

For bonus points:

  1. The default source from the console demo of Python.net will require a command line argument; modify the sample code to invoke app.py with the contents of app and app_packages in the PYTHONPATH for the purposes of execution.
  2. The output app should be a gui app, not a console app. When MyProject.exe is executed, a black console window should not be displayed.
  3. Add a target to the solution file that produces an MSI installer with contents of the "MyProject" directory, including the executable, embedded python, app_packages and app.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment