Timur Fayl
Timur Fayl

Reputation: 19

A way where to keep and how to copy python files to C# project output directory

I have a C# project which works with python web server, written with FastAPI. Server is a part of C# application, and runs and shuts down by C# app.

I usually work only with C# apps and have no experience in cases, when there are two or more projects in repo, which form one app, but written in different programming languages. So, I'm interested in two things:

  1. Is there any common practice where to keep python files in repo with C# solution (e.g. in C# solution folder or somewhere else)?
  2. How to copy python files into C# project output directory on build? I know about call of "Copy" function in csproj, but maybe there are other approaches available? There is an option in Visual Studio to create Python project (pyproj), and I hoped that it is possible to create a reference from C# project to Python project, to copy python files automatically on build, as it is happens with C# dependencies, but it didn't work for me. Does anyone know if such option available?

Upvotes: -2

Views: 81

Answers (1)

Fei Xu
Fei Xu

Reputation: 476

Manually adding post-build events to .csproj file can ensure your .py file copied to the output directory:

<Target Name="CopyPythonFiles" AfterTargets="Build">
      <Copy SourceFiles="(yourFileName).py" DestinationFolder="$(OutDir)" />
</Target>

Upvotes: 0

Related Questions