I have a .NET Core class library project ClassLibrary1
created in Visual Studio 2015. In this class library project, I added a folder NewFolder
that will be used by whichever project is referencing ClassLibrary1
.
So for instance, I have a project called ConsoleApplication1
that references ClassLibrary1
. Every time I build ConsoleApplication1
, NewFolder
should be copied
FROM
PROJECT_PATH\ClassLibrary1\bin\Debug\net452\win7-x64\NewFolder
TO
PROJECT_PATH\ConsoleApplication1\bin\Debug\net452\win7-x64\NewFolder
UPDATE:
I added the following to the project.json
file of my ClassLibrary1
project.
"buildOptions: {
"copyToOuput": "NewFolder"
}"
It only copies the the folder to PROJECT_PATH\ClassLibrary1\bin\Debug\net452\win7-x64\NewFolder
but not to PROJECT_PATH\ConsoleApplication1\bin\Debug\net452\win7-x64\NewFolder
every time I build ConsoleApplication1
.
I have no idea how this should be done in .NET Core projects because this does not seem to be the behaviour for non .NET Core projects.
UPDATE 2:
In non .NET Core projects I simply add a script to the post-build events command line of ClassLibrary1
and it automagically copies everything in the ClassLibrary1/bin/Debug
including files and folders to ConsoleApplication1/bin/Debug
.
xcopy "$(ProjectDir)NewFolder" "$(TargetDir)NewFolder" /E /Y
Add the file to your project, then in the file properties select under "Copy to Output Directory" either "Copy Always" or "Copy if Newer".
Use the CopyDirectory method to copy a directory to another directory. This method copies the contents of the directory as well as the directory itself. If the target directory does not exist, it will be created.
The bin folder holds binary files, which are the actual executable code for your application or library. Each of these folders are further subdivided into Debug and Release folders, which simply correspond to the project's build configurations.
In the Name text box, enter "StringLibrary" as the name of the project. Select OK to create the class library project. The code window then opens in the Visual Studio development environment.
Copy to Output Directory is a property for files within a Visual Studio project. Select a Windows Form in a project, find Copy to Output Directory and note Copy to Output Directory is set to [Do not copy].
When you use a Visual Studio project template to create an app, Visual Studio automatically creates required settings for Debug and Release build configurations. You can change these settings if necessary. For more information, see the following articles: For the debugger to attach to a C++ DLL, the C++ code must emit DebuggableAttribute.
For files, residing outside of the project folder working with Post build events provides the capability to copy files to the build folder of a project. Select project properties. Select the Compile tab for VB.NET, Build Events for C#.. In the bottom right hand corner select the Build Events... button (VB.ET only).
What I usually do in non .NET Core is create a link to the folder/item in the project (your case ConsoleApplication1
and then set it to be copied to output.
any way, this can't be done in .net core.
What you are doing is also wrong, the project.json of ClassLibrary1
does not copy files to the output of ConsoleApplication1
what you should do is add the following to your project.json
of ConsoleApplication1
"copyToOutput": {
"mappings": {
"NewFolder/": {
"include": "../ClassLibrary1/bin/Debug/net452/win7-x64/NewFolder/**"
}
}
}
mappings
- defines the folders to copy to (NewFolder
) (the /
is apparently necessary)
include
- Defines glob patterns and file paths to include for copying to build output.
you can embed your files using buildOptions and accessing it using
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "MyCompany.MyProduct.MyFile.txt";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With