Run T4 Text Template when click update button or application restart - c#

In my application, some setting are coming from JSON settings file. The setting file can be updated from within the program and a .cs file is created from these updates with using T4 Text Template. So when the JSON file is updated, I want that the T4 Text Template also works and update the .cs file. If this is not possible, I would like the T4 Text Template to run and also update the .cs file when I restart the program. But I have no idea how to do it. I managed to create .tt file and it works perfectly when I save .tt file in the Visual Studio.
Note: I have googled for 2 days and read all topic in the site. But I did not reach any result.

You can run command-line transform tool. Here’s an example:
"C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\TextTransform.exe" "C:\src\template.tt"
That will use TextTransform.exe from VS2015. VS2017 also has TextTransform.exe, even the freeware community edition, it's located in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\
Documentation for the CLI is available.

Related

Generating a file during "Build", c#, Visual Studio

How can I generate a file during "Build" in Visual Studio using C#?
I want to create a .txt File and add some text in it. The file should be created directly when I press Build and save it in a place where the Release or Debug Folder is.
You should have a look at build events.
Typically you can run any kind of script pre and post build - including the (re)generation of a text file.
To copy files into the output path, you can use the OutputPath variable. See the MACRO section and this list on how to use them.
As by #Oliver's comment: if it is a static file, you can just include it in the project using its properties and select: Copy if newer.
Taken from the documentation:
And a subset of the MACROs

My main .cs file is now blank after crash

I've just had a visual studio crash (2012 - Using Monogame) and now my main.cs file in my project shows up as a blank text file when opened in Visual studio.
The file itself still shows as 134kb so it isn't blank? No matter what I do the project cannot find the file .. every other .cs file is fine.
There is no backup that I can find .. I'm hoping there is some way of reading the file and recovering the code.
Monogame does not have a main.cs file.
I will assume is is user created. The Main() function is in Program.cs.
I would suggest moving to VS 2022 Community Edition, it is free, and Monogame 3.8.1.
Create a new project and copy all of your class files into it, modifying the namespace of each to match the new name.
Copy your content sources and add them with the mgcb-editor.

Custom Visual Studio solution

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.

Visual Studio, Xamarin Forms, creating .resx file isn't creating Designer.cs file

I read this post about .resx files having a corresponding .designer.cs file that is generated when you create a new .resx file in Xamarin studio. I am using .resx for localization in my Xamarin shared project.
Unfortunately as of 24 Aug 2017 and version 15.3.2 , it seems that you are no longer able to create a .resx file through the Add->new item solution wizard.
One solution is to create a .resx file outside of VS, and then use the Add->Existing Item solution wizard, and the .designer.cs file is supposedly generated automatically. (this did not work for me)
Another solution is to change the file format of a .txt file in the solution wizard, and then run the custom tool ResXFileCodeGenerator in the AppResources property field. (This also did not work for me)
One final solution I found is to programmatically create the designer file, but I couldn't get this code to run, and surely there is a better solution.
So my question is:
What is the correct way to create a AppResources.resx file, with a corresponding AppResources.designer.cs file in Visual Studio Community 2017 Version 15.7.3

What is the easiest way to make a backup in visual studio 2013?

I want to make a backup from the whole project. I also need to rename every backup. I'dont like the way to copy the project folder and rename the folder and the project file.
I've already tried to make it like that:
http://jasonfaulkner.com/VisualStudioExpressProjectBuildBackups.aspx
But it doesn't work, I am always getting the error "Invalid parameters"
Does anyone already tried this?
Thanks
The DPack extension for Visual Studio includes the Solution Backup tool that creates a zip archive of the solution and auto names it.
Manually edit .sln file
This method is entirely aimed at renaming the directory for the project, as viewed in Windows Explorer.
This method does not suffer from the problems in the Remove/add project file method below (references disappearing), but it can result in problems if your project is under source control (see notes below). This is why step 2 (backup) is so important.
1- Close Visual Studio.
2- Create a backup of your .sln file (you can always roll back).
3- Imagine you want to rename directory "Project1" to "Project2".
If not using source control, rename the folder from "Project1" to "Project2" using Windows Explorer.
4- If using source control, rename the folder from "Project1" to "Project2" using the functions supplied by source control. This preserves the history of the file. For example, with TortoiseSVN, right click on the file, select TortoiseSVN .. Rename.
5- In the .sln file, edit all instances of "Project1" to be "Project2", using a text editor like NotePad.
6- Restart Visual Studio, and everything will work as before, but with the project in a different directory.
Alse would recommend TFS, a powerfull tool to do what you pretend. You will be able even to recover previous versions of specific files,if you have any error and you have troubles find it you can see what changes you did since last "check in " etc. There are many options

Categories

Resources