How to copy files without code with a compiled project when linking to another project in C #

I have a project that acts as a shell for a third-party .exe (it has static methods for creating a command line and running an executable file). I want to use it in at least several projects in my solution. Ideally .exe should only be in this shell project (I don't want to add it to every project that uses it). Right now I'm trying to get this to work with a web project (.NET MVC) running on IIS 7, but when I use Assembly.GetExecutingAssembly().Location , to see the directory from which my shell is being called, is in a folder like

C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET Files \ "My Project" \ 65a016fb \ ac5f20a7 \ build \ DL3 \ d8de0f10 \ 06e277a2_55b2cd01

and my third-party .exe file was not found anywhere. Can I copy files with links that do not compile?

Btw, I set the properties "Copy to output directory" and "Create action" of my .exe to "Always copy" and "Content" / "Resource" / "Embedded resource" so far.

+6
source share
2 answers

Try adding existing files to your projects that use your wrapper. When the dialog box appears, do the following:

http://wiki.oxygenelanguage.com/en-w/images/0/0d/AddAsLinkAero.png

Either this, or drag the necessary files into your projects from wrapped Alt .

This will add the files as links. Links are a good choice for reuse when source files should be in a single place.

Adding files as links in combination with setting the assembly action of links to Content and Copy always to be able to copy them to the output directory should work for yours.

+1
source

If anyone encounters this problem, here is how I got around it:

  • Add .exe to your project resources (right-click on the project, Properties → Resources, add the file and give it the name of the resource)
  • Now you can access your .exe as byte[] (at least if you are creating a dll) with Properties.Resources.*NameYouGaveYourResource*
  • Before using your .exe, use File.Exists() to check if the file exists in Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) (or you can put the exe where you want using the method above which you get the directory .dll) - if not, write the file:

using (FileStream fileStream = new FileStream (Path.GetDirectoryName (Assembly.GetExecutingAssembly (). Location) + "\ EXE.exe", FileMode.CreateNew)) {fileStream.Write (Properties.Resources.NameYouGaveYourResource, 0,> Properties.Resources .NameYouGaveYourResource.Length); }

Now you can easily use exe as a Process . Pretty far from ideal, but that means exe accompanies your .dll wherever it is.

0
source

All Articles