I have a template service that uses RazorEngine to generate HTML for email sending.
I want to make it easy to add a new template to the project, meaning that I don't want to specify the file build action.
Is there a way where I still have the .cshtml file in my project with intellisense and etc. but it automatically will set their build action to Embedded Resource?
Here is a example of my project structure
Wildcard inclusions in C# project files
However, we can use wildcards when specifying these files. Here is an example that includes all .py files from a folder (and all subfolders):
EmbeddedResource Include="Python27\Lib\**\*.py"
Once you save the project file and reload it in Visual Studio, you will see that the Solution Explorer understands the wildcard and will populate with all files that match it. You can copy new .py files into the target directory and Solution Explorer will update accordingly (you need to click the “Refresh” button for this). And while it shows the results of the wildcard inclusion, it does not alter the entries in the project file unlike the behavior of the Add Files dialog.
Related
I have a WPF project that is now finished, and I want to publish the app into an installer that other people can use.
When I publish the project, the project compiles into setup.exe, but on install the folders that I have do not get included.
I've been reading the guides, and made sure to include the files inside the folders as Content or a Resource. I've also made sure they are always copied. When some of my files are copied, they have a .deploy extension, and I need it to be an .xml in order for some function to read them. Images that I have in the app load fine however.
What do I need to do to have my custom files be EXACTlY as they are, xml as xml, txt as txt and so on. Also I have some empty folders, like this TempCF that I use at some point. Do i need to create it via code?
If you go to Project->Properties->Publish->Install Mode and Settings->Options->Deployment in Visual Studio, there is a "Use ".deploy" file extension" option that you can untick to get rid of the .deploy extension being added to your published files:
Empty project folders are not included in the output. Either put a dummy content file in them or create the folder dynamically as needed during runtime.
# Nikola L.
You could try to use the following methods to add the files in your program to the installation package so that you can have the files you need in your installation path. If I misunderstood your question, please let me know.
The steps are as follows:
1.Right-click on the Setup project and select View -> File System
2.In the File System page, right-click the Application Folder (File System on target Machine) and select Add->Folder(named User's Application Data ) -> File…-> find the file under your project and select the file you need.
Such as:
3.Right-click the Setup project.
Install your setup package.
You can find the files you added in your installation path.
The result is like the picture below:
I have a website that I'm developing with ASP.NET. I'm using Visual Studio 2015. When I right-click and hit publish website the site publishes correctly except that my resources folder gets left behind. Heres what the solution explorer looks like in Visual Studio
But after I publish it here are the files that get put on Azure (accessed via FileZilla)
How do I tell Visual Studio to publish the Resources folder with the rest of the website?
Likely Answer
Open the Solution Explorer.
Right click one of the files in the Resources directory.
Choose Properties.
You now need to set two properties.
Build Action Content
Copy to Output Directory Do not copy
Do this to all the files that you would like to publish as content to the web server.
File Properties for Web Server Content
Remarks on File Properties
The Build Action property indicates what Visual Studio does with a file when a build is executed. Build Action can have one of several values:
None. Not what you want. The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file, that you do not want to publish to the web server.
Compile. Not what you want. The file is compiled into the build output. This setting is used for code files. In other words, we compile the file and the stick it into the bin directory.
Content. This is what you want. The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file. The "Content output group" is a list of files that Visual Studio will publish while also maintaining the same directory structure.
Embedded Resource. Not what you want. This file is embedded in the main project build output as a DLL or executable. It is typically used for resource files. In other words, it not only goes into the bin directory but is also embedded within a .dll or .exe file.
Copy to Output Directory. This property specifies the conditions under which the selected source file will be copied to the output directory. The output directory is normally the bin.
See Also
What are the various "Build action" settings in Visual Studio project properties and what do they do?
File Properties on MSDN
If like me you are using Visual studio 2019, just right-click on the folder and select publish "name of the folder"
Steps to add resources to be published (Visual Studio 2017):
1) Right click the resources folder and select "Include In Project"
2) Now you should see Build Action: Content on the properties for the images.
Make sure the contents of your Resources folder have the proper "Copy to Output Directory" property. Right click the files you want to copy over, select Properties, then in the Advanced section look at the value under Copy to Output Directory. Generally this is set to "Do not copy" by default since most things get packaged up in the .dll. Change it to "Copy if newer" to get it to bring over the file. It'll bring over the folder structure as well.
I'm planning to build my winform into a .exe file. I'm just wondering what to do with the XML files that my application needs?
I did some research and found out that I can add the XML files in the Resource folder before creating a .exe file.
Or I need to create a setup file? When the user runs the setup file, the XML files will be installed into their pc.Now I wonder which one is the best way to go for,
Note: XML files might get modified by the user.
If you want to ship the XML files as seperate to the .EXE then you can set the Copy to Output Directory to Copy if newer. (click on file and then go to properties).
OR if you want it as part of the .EXE I think you can change the Build Action to Embedded Resource.
I personally would create a Setup as per your edit and include the XML files. I usually just add everthing from the bin/release folder that is needed when I create a setup file.
You could either deploy the necessary files along with the executable in the same folder or embed them as resources (if they are read-only). If you need to modify them do not embed them as resources into the executable.
The correct way depends on how you intend to use the files. If the files always are deployed together with your application, the application never writes to them and they are never upgraded without upgrading the application, you can go with them embedded as resources.
If you need to update them separately from the application, you need to have them as physical files.
You don't necessarely need a installation package, unless you need to apply some logic during setup, such as updating the content of the setup based on user input or to check preconditions. The application can just be copied into place regardless of if you have embedded the files or not.
When I write my APIs for applications I always follow a set pattern (who doesnt!?) that looks like this:
User (Folder/Namespace)
User.cs
UserDao.cs
UserDaoFactory.cs
UserService.cs
UserServiceFactory.cs
I know Resharper has file templates which I already utilize, but it would be great if I didn't have to individually add each file which can get extremely tedious when you are working with upwards of 30 entities in an app. If you can't do this with resharper is there anyway to make some kind of macro with Visual Studio that will execute your resharper file templates?
Create all these classes in a single file (create a file template containing the set of standard classes if you want to)
Write your logic
Press Shift+Alt+L to put focus on the file in Solution Explorer
Press Ctrl+Shift+R to display Refactor this menu with a list of applicable refactorings.
Select Move Types into Matching Files, complete the refactoring wizard, and watch the classes separating into individual files.
To put all the newly created classes into a folder, select them in Solution Explorer, and again invoke Refactor this.
This time, select Move to Folder.
Specify the name of the new folder in the refactoring wizard, press Create this folder, and complete the wizard.
Looks like R# 8 added this feature
From the Resharper Help Page
Starting from ReSharper 8.0, each file template can add more than one
file when it is applied. This > may be helpful for WPF, Web and other
projects where related data can be saved in different files.
Here are a few things you need to know about multi-file templates:
A file template always include one main file, and, optionally, any
number of secondary files. So as soon as you add a secondary file to
any file template you get a multi-file template.
When adding a
secondary file, you can reference any existing file template (Add file
from existing template option). Note that if the referenced template
has multiple files too, then only the main file of the referenced
template will be added when you apply the template.
The set of
parameters spans all files of a multi-file template. I.e., if you use
the same parameter $PARAM$ in several files of a multi-file template,
it will have the same value in all related files when the template is
applied.
If a multi-file templates has editable parameters, the Hot
Spot Session, which deploys when you apply this template, will guide
you through all created files where the user input is required.
I would consider using .tt templates with ReSharper.
create master file with ReSharper.
using one or many tt files to auto generate dependent (.partial.cs) files with partial keyword in it.
extend generated classes if needed.
I have a .NET C# 2.0 Project and it refers to many .xml files, i'd need these files when i port my project to another location or distribute it. I'm currently not interested in making it as a setup.exe file. I want to to be standalone. currently i've got all of them in a folder "FILES" within my project. So what i want to know is
Can i pack all these XML files inside a dll, so that it's secure and portable? If so how to do it?
When i build the program the FILES folder is not copied. How can i make it copy it as well?
You can mark the xml files as resources, and they will be packaged inside the assembly. Just set the "build action" to "embedded resource". Alternatively, use a resource file (resx), and drag the xml files onto the resx designer, and it'll do everything for you (including providing access methods to get the data back out).