Custom Visual Studio solution - c#

I'm using these tools and technologies:
Visual Studio 2019 CE
Windows 10
SQL Server
C# and ASP.NET MVC
Currently I create a new Visual Studio 2019 solution.
Add three/four nuget packages (automatically targets MVC).
Change a couple of files.
Setup configuration files.
Add standard/default project images.
I now start to develop the site as required.
I will check-in the project into Azure DevOps at the end of the day.
Is there a way to do the above 4 steps by the means of a template/package that I set once so in future I can click a few buttons in Visual Studio and all 4 steps have been done for me rather than having to do each step manually?
Errors
Error 1
This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props.
After attempting to Restore the packages
Error 2
An error occurred while trying to restore packages: Unable to find version 'XXXX' of package 'AAAA' C:\Program files(x86)\Microsoft SDKs\NuGetPackages: Package 'AAAA' is not found on source C:\Program files(x86)\Microsoft SDKs\NuGetPackages.... https://api.nuget.org/v3/index.json Package 'AAAA' is not found on source https://api.nuget.org/v3/index.json

There is something called a multi-project template. That same page has a specific section on creating a multi-project template from an existing solution:
Create a solution and add two or more projects.
Customize the projects until they are ready to be exported to a template.
On the Project menu, choose Export Template.
The Export Template Wizard opens.
On the Choose Template Type page, select Project Template. Select one of the projects that you want to export to a template, and then
choose Next. (You'll repeat these steps for each project in the
solution.)
On the Select Template Options page, enter a name and optional description, icon, and preview image for your template. Choose Finish.
The project is exported into a .zip file and placed in the specified output location.
Create a directory for your template, with a subdirectory for each project.
Extract the contents of each project's .zip file into the corresponding subdirectory that you created.
In the base directory, create an XML file with a .vstemplate file extension. This file contains the metadata for the multi-project
template. See the example that follows for the structure of the file.
Be sure to specify the relative path to each project's vstemplate
file.
Select all the files in the base directory, and from the right-click or context menu, choose Send to > Compressed (zipped)
folder. The files and folders are compressed into a .zip file.
Copy the .zip file into the user project template directory. By default, this directory is %USERPROFILE%\Documents\Visual Studio
\Templates\ProjectTemplates.
In Visual Studio, choose File > New > Project and verify that your template appears.

Related

Add folders to a c# projects using dotnet cli commands

I know this can be done via Visual Studio. But I wanted to know if there is a command or a workaround to add folders to a project.
My projects are: Class Libraries a project for creating a class library that targets .NET or .NET Standard
I tried with a shell script:
mkdir DTOs;
mkdir Behavior;
mkdir Features;
mkdir Filters;
mkdir Interfaces;
mkdir Mappings;
mkdir Wrappers;
folders are created but they are not added to project.
Thanks in advance.
Please check out the following detailed answer by poke.
Paraphrasing it for reference here:
Project folders
In modern .NET Core projects (using the .NET SDK), files are automatically added based on a global file pattern. For example, any .cs file anywhere within your project directory is by default automatically configured to be a part of your project that needs to be compiled. This pattern however only applies to files, not directories.
Directories are not an explicit part of a project by default. Instead, they are only there if they are “needed” for a path to a file. That’s why you won’t see folders within Visual Studio until there is a file that is part of the project.
If you are within your project folder and then add a folder there, you will not see the folder there. But as soon as you add a file to that folder (echo '' > TempFolder\Test.cs), it should automatically be picked up by Visual Studio:
You can also enable the “Show all files“ option in the solution explorer, to make folders that are not part of the project appear in the solution folder:
As you can see, the folder appears as a transparent item because it is not part of the project itself. You can then right click on the item and choose “Include In Project“ to make this folder an explicit part of the project. This action will add the following section to the project file:
<ItemGroup>
<Folder Include="TempFolder\" />
</ItemGroup>
This basically tells Visual Studio that the folder is part of the project even though it does not contain any files. As soon as you do add any file to the folder, Visual Studio will remove that configuration though since the folder is now again an implicit part of the project.
Solution folders
Visual Studio solutions don’t show the actual directories within your solution directory but rather a virtual directory as configured within the .sln file. Projects being located within subdirectories will not automatically be located within such a folder within the solution structure, and similarly non-project folders will also need to be added to the solution file first.
There is no mechanism to manage the solution folders with the dotnet sln command though. The only thing that you can do is add a project into a particular virtual folder within the solution:
dotnet sln add path/to/project.csproj --solution-folder VirtualFolder
This would add the project.csproj inside the VirtualFolder solution folder within the Visual Studio solution.
If you want to manage the solution folders otherwise, you should do that with Visual Studio.

Create project and its own sln file within multiple project solution

We have a large server-side C# solution at work. It has multiple projects, each with its own sln file on the first layer of the application's directory. It also has a general all.sln which contains all the projects.
I have added a new project which builds successfully, but a sln file for this individual project has not been created. How can I create it in VS 2013, so it appears alongside the other sln files?
Any help at all would be appreciated. I need to do this so that the BAT file we're using has a sln file it can use.
You should create an empty solution, save it at the proper location with the proper name, and add the desired project to it.
To create the empty solution:
File > New Project >
Other Project Types > Visual Studio Solutions >
Blank Solution

Creating a project for web assets in Visual Studio 2013

I have multiple ASP.NET MVC5 projects that use several similar styles/scripts, and I think, for maintenance's sake, it'd be ideal to have a separate project in Visual Studio 2013 containing the LESS stylesheets and JavaScript files that can be shared between the two.
My setup is as follows:
Web.Project1
Web.Project2
Web.Assets //would contain LESS/JS files
Resources
Domain
Data
Any pointers?
I've been looking at adding as a link, but I'm not certain that would accomplish what I need.
I recently went through this process for a project of mine, and concluded that if your goal is simply to avoid duplication by keeping your code DRY then using linked files works great.
It's simple enough to do, but I'll write it up anyway as it might save someone some time.
Quick Summary
Create common Solution Folders containing the resources to be shared, or simply designate one of the projects to be the master.
Use "Add as Link" to add the shared resource files to each project as needed.
Add an AfterBuild task to each project file that will copy the linked files to project folders. This is only needed so that Visual Studio test/debug (F5) will work locally.
Detailed explanation follows:
Configuring Solution Folders for the Shared Resources
** Note that if you're simply going to share files directly from one project to one or more additional projects then you can skip this step.
Visual Studio solution folders do not have to reflect physical file system folders, but doing so will help preserve your sanity. So first create the folders on your local file system and copy the resource files into them. The new folders should be located under your solution folder. For example:
\MySolution
\Common
\Images
\Scripts
\Styles
Back in Visual Studio, right click on the Solution Items folder and use Add Solution Folder to replicate the new file system folders.
Next, add the files to the new solution folders by right-clicking each folder and using Add Existing Item to add the contents of the folders.
Add Shared Resources as Links
For each project that will use the shared resources, right-click the project folder and choose Add Existing Item. Browse to the common folder, select the desired files, click the drop-down arrow next to the "Add" button and choose "Add as Link".
You may get a source control warning about adding files that are outside of the project directory structure, but this can be ignored since the linked file will be under source control at its source.
Add an AfterBuild Task to Copy Files
When you publish the application to a server the linked files will copied to the project folders to which they are linked and everything works as expected. However, in the development environment the linked files do not physically reside in the project folders. So when you hit F5 to test your application in VS, the shared resources will be missing.
The simple solution is to add an MSBuild task to copy the linked files from their source after each build. This needs to be done to for each project that contains the shared resource links.
Right-click the project and choose Unload Project. Right-click the project again and choose Edit <ProjectFileName>. Scroll to the bottom and add the following (just above "</Project>"):
<Target Name="AfterBuild">
<!-- Copy linked content files to local folders so that they are available in the debugger.
This is only an issue when running the application locally. The linked files should
be automatically published to the correct folder when publishing to a web server. -->
<Copy SourceFiles="%(Content.Identity)"
DestinationFiles="%(Content.Link)"
SkipUnchangedFiles='true'
OverwriteReadOnlyFiles='true'
Condition="'%(Content.Link)' != ''" />
</Target>
** Copy task adapted from this link.
Save the project file then right-click and choose Reload Project.

make VS2012 get the added files of a TFS solution

I am new in TFS, i have did GetLatestVersion but all newly added file in TFS was not getting in visual stdio but i can see those added file in TFS Server. Please suggest?
Click on the Show All Files in solution explorer to see the newly added file. It will be greyed out. Right click on the file and select Include to get it added to your project or soltion.
Common problem is that file will be present in source control but not included into the solution.
You can do it this way:
File > Source Control > Advanced > Open from Source Control
Find you Team Project
Open its .proj, .sln file, whichever is appropriate
Select 'Yes' / 'Overwrite' if it says you have the same files locally
This will ensure you get all the files from source control, rather than just those in your local project definition.

how rename a folder inside project template to project's name? (visual studio template customization)

I created a project template in Visual Studio 2010. When I click on Project -> File -> Export Template, I get a zip file in the Visual Studio template folder. In the solution, I have a folder named Test.
When I create a solution from that template (from add -> new project dialog), I want to rename the Test folder's name to the solution's name automatically.
How can I do that?
Get the files out of the zip file
In "MyTemplate.vstemplate", change TargetFolderName="Test" to TargetFolderName="$projectname$"
In the .csproj file, change everything that refers to folder "Test" to "$projectname$" (including paths, etc.)
This should work.
Additional info:
https://msdn.microsoft.com/en-us/library/ahkztdcb.aspx (Visual Studio project template info)
https://msdn.microsoft.com/en-us/library/eehb4faa.aspx (Visual Studio template macros reference)

Categories

Resources