简体   繁体   中英

Run a C# file as a pre-build event Visual Studio (.NET Core)

I have a C# file that manipulates some files in a given directory.

The files I want it to manipulate are files that lie within the working directory of my project and need to be updated when the build becomes out of date. How do I run this simple C# source as a pre-build event?

Ideally, I want to be able to compile it for cross-platform. Currently, the target project is a .NET Core project.

Do I compile the small C# source as a single executable and then place that in the target project? That seems inefficient. Is there a way to do it where I put this small C# source into a project within the same solution as my target project, then run that new project as a pre-build event?

Maybe you are new to .NET Core but have other programming experience. If so, continue reading, it's about a mental bias you may need in order to develop using .NET Core. I can assure you it's for good.

I have a C# file that manipulates some files in a given directory.

C# file cannot manipulate anything, it's just some C# code. In order to do anything else then edit, delete, or compile it you have to make it part of a project, compile the project and run it, say, applying it to the folder you need in your case.

So, yes, you need an executable in order to run it .

The files I want it to manipulate are files that lie within the working directory of my project and need to be updated when the build becomes out of date .

.NET Core handles all these - you shouldn't do anything. Search for Application Lifecylce Management (ALM) and get familiar with it.

Ideally, I want to be able to compile it for cross-platform .

.NET Core is cross-platform by itself, you shouldn't care about it. It's the java's dream "compile once run everywhere" come true.

So, as a bottom line - keep your life easier not thinking of such fictitious issues - someone has already taken care of all these.

Unless you have something else in mind, which unfortunately, I cannot figure out from your question.

And a final remark, or a word of warning if you will - .NET is all but an amateur set of tools. You should spend a great deal of time on it, but you'll be much grateful at the end.

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM