Visual Studio: How to automatically copy custom file to output directory only when publish website? - visual-studio

I got some files necessary for the hosting environment, e.g: robots.txt as in the attached image.
But I don't want to store them in Visual Studio solution, because they are not a part of my project, it will be confusing to have these under the solution folder or source control.
So, I am thinking is there anyway to let Visual Studio automatically copy these files from my custom location (e.g: D:\HostingPrepareForST\ ) to the output folder when I hit "Publish" to publish the website?

Related

How to turn visual studio files into actual app that can be sent/ downloaded and run by another user?

I have a finished project with a bunch of different winform files. They are linked between eachother through a menu file. How do I go from having this project as a visual studio application file to an actual application, with customized icon and that can be opened by a user from another PC (which doesn't have Visual studio). I don't want to just zip them.
I didn't try anything and this might be a newbie question but what I expect is basically to have an actual app instead of a bunch of files.
When you compile the winforms project you get a bin folder and a Debug/Release folders inside.
A simple way to deliver the app is just copy the Debug folder that have the .exe and dll files to the dest PC.
The best way is to follow this guide:
https://learn.microsoft.com/en-us/visualstudio/deployment/quickstart-deploy-using-clickonce-folder?view=vs-2022
Or make an autoinstaller

Visual Studio 2022 Custom Project Template doesn't show after unzipping / zipping

I have created a new Project Template by exporting a project via Project -> Export Template. Opening Visual Studio now, I can see my template showing up.
I then went to
Documents\Visual Studio 2022\My Exported Templates
and moved the MyTemplate.zip to another folder. Went to
Documents\Visual Studio 2022\Templates\ProjectTemplates
and made sure that MyTemplate.zip is not in there as well.
Now when I open VS again, I can see that my template is not available anymore.
To counter check, I moved the zip back into Documents\Visual Studio 2022\Templates\ProjectTemplates , reopened VS and made sure that the template is visible again.
I then went ahead, extracted MyTemplate.zip and compressed it into a zip again (Right Click -> Compress to Zip). Now when I move that zip into Documents\Visual Studio 2022\Templates\ProjectTemplates and restart VS, the template does not show up.
Bottom line, I am unable to import any template that I have manually compressed into a zip archive, seems like something is happening to the zip during extract / compress. I have been testing this on Win 11 with the OOB zip tools as well as nanazip.
Did you try extracting your template project ZIP file?
I was struggling as well but as soon as I extracted my custom template project with the rest of the Default templates it started showing up.
VS template is looking for folders in the ..\Visual Studio 2022\Templates\ProjectTemplates\ not a zip file. If you want your template to show up, move its folder there.
In my case the problem was that I named the XML file .vstemplate. It needs to be something.vstemplate.

How Do I Compile Copied and Pasted Files in a Visual Studio Project Solution?

I just created a new project in Visual Studio 2019 and copied a bunch of files into the source/repos/project directory but they don't compile. I am guessing that is because these files were not created using Visual Studio.
Is there an easy way to make sure that the Project compiles all files in the directory even if they were created elsewhere? Right now all the files that I pasted in are treated like hidden files and the build option is a greyed out "None" instead of "Compile."
The files in question are all folders, PHP files, CSS, Javascript, etc.
See screenshot
enter image description here

Getting directory of current project, and not visual studio plugin

I am currently trying to write a plugin for visual studio that accesses the bin folder of the currently open project in Visual studio. However, all the solutions I have come across simply return the bin folder and directory of the plugin that is I am writing. For example, I have used the method detailed in the article below, which claims to return the current project's directory.
How to Access Bin Folder of Active Project using visual studio 2010 add in
path = System.IO.Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;
System.Windows.Forms.MessageBox.Show(path);
Is there anything I am missing on how to make this work?
A Visual Studio project can have several project configurations, each one with a different output build folder that is set in the project properties window, Compile/Build section, Build output path. Furthermore, the output build folder can be absolute or relative to the project folder.
The code of this article gets the absolute output build folder for the active configuration of each project of a solution:
HOWTO: Get the output build folder from a Visual Studio add-in or macro
http://www.mztools.com/articles/2009/MZ2009015.aspx

Create Visual Studio Solution from Batch File

Visual Studio seems to consist of a single solution file (*.sln) along with one or more project files (a C# project would have the *.csproj extension).
I have been playing around with a console application that parses existing directory entries to create solution files with the associated project files.
It works, but every time I run into a new project here at work I find myself spending a week or more debugging my console project so that it can churn out a solution for that particular work project.
Is there something out there already that can create a VS solution out of an existing file structure?
As you can tell from my screen capture below, these projects are nested very deep, so it would take a very long time to do this with the apps folder below with the "by mouse" technique in the Visual Studio IDE.
I created the custom console application that is posted in this post:
https://stackoverflow.com/a/22153536/153923
I invite others to contribute how they approached this solution, though.
So, I found out today that this feature already exists in Visual Studio.
Link 1: How to: Create a Project from Existing Code Files
Link 2: How to: Create a Project from Existing Code Files
Basically, though, it says this (just in case the MSDN links get changed or deleted):
You can create a Visual Studio project from an existing app—for example, an app that you obtained from an online source. Project and solution files are created on your computer and the other relevant files are added. A project can be created from Visual C++, Visual Basic, or Visual C# code files.
Security note Security Note
We recommend that you determine the trustworthiness of existing code files before you import them into Visual Studio, because Visual Studio will execute some of the code in a fully trusted process when you open the newly created project.
To create a project from existing code files
On the menu bar, choose File, New, Project From Existing Code.
The Create New Project from Existing Code Files wizard opens.
Use the wizard to specify the details of the existing code files that will be added to the project and the application that will be created when you build the project.
Another good answer was given by cbp in Visual Studio: Create a web application from existing code:
--
OK I figured it out. It's weird, but the following steps will work:
Open fresh copy of Visual Studio
File->New Project, select Web Application
Use the following settings:
Name: Website (this is the name of the existing folder with the website files in it)
Location: C:\Temp\ (anywhere will do for now)
Solution Name: TheProject (name of the existing project's root folder)
Check "Create directory for solution"
Delete the auto-created Default, Global and Web.config files
Save All and close Visual Studio
In Windows Explorer, copy the new folder on top of the existing folder so that the files are merged.
Double click on the sln file to open Visual Studio again.
Select "Show all files" (at the top of Solution Explorer)
Right click on any files or folders you want to add and select Include in Project.
Great idea!

Resources