How to add generated code files in VS 2010 as dependent files? - visual-studio-2010

I am automating my project using T4 templates. For this, I have to write some repeated code using T4 template and some hand written code which should not be overwritten by the T4 template. I would like to add the generated code file as the dependent file of the handwritten file. I am following convention of class1.cs for handwritten file and class1.generated.cs for generated file. How can I add this generated file in the project as dependent file of class1.cs?

To do this programmatically you'll have to modify the .csproj file directly. Refer to this question for details:
In Visual Studio (2008) is there a way to have a custom dependent file on another custom file?
If you want to do this via the IDE then use the VSCommonds Add-in for Visual Studio 2010.

Related

Is it safe to delete .dsp and .dsw files?

I've been given a Visual Studio project which has come with the following files:
myproj.def
myproj.dsp
myproj.dsw
myproj.idl
myproj.vcxproj
myproj.vcxproj.filters
After reading the Project and Solution Files Microsoft Docs it says for Projname.vcxproj:
The project file. It stores information specific to each project. (In earlier versions, this file was named Projname.vcproj or Projname.dsp.) For an example of a C++ project file (.vcxproj), see Project Files.
And this Microsoft Docs page says:
For convenience, Microsoft Visual Studio 6.0 provides a project file for each sample. This file has the DSP extension. An Allsamp.dsw workspace file is also provided in the main directory so that you can compile all the samples at once from within Visual Studio.
Does that mean that if I have the .vcxproj file, I can safely delete the .dsp and .dsw files?
Assume I do not care to ever recompile using Visual Studio 6.0 in the future.
.sln is equivalent to .dsw in VC6.0
.vcxproj is equivalent to .dsp in VC6.0
As far as I'm concerned ,if you have the .vcxproj file , you can safely delete the .dsp and .dsw files?

Code generation in Visual Studio based on all files with a given extension

I have the following task: Make a visual editor in Visual Studio (not the core of today's question) which results in a text file, on a custom format. This file will then be used as input for code generation resulting in C# code. For this, I've been looking at:
T4
Visual Studio Extensions
Visual Studio Project Templates
Visual Studio Item Templates
I feel the solution is there somewhere, but I can't quite figure out how best to do it. As I see it, the main problem is somehow to automatically generate code for all files with a given extension. Does anyone know of any tutorials or descriptions on how to do this?
Thanks in advance!
To automatically associate a code generator with all files of a given extension, you need to
Create a Visual Studio package
Implement a custom IVsSingleFileGenerator. The easiest option is to subclass the BaseTemplatedCodeGenerator and override its GenerateCode method to supply your own T4 template as the "inputFileContent".
Use the ProvideCodeGeneratorAttribute to register the generator.
Use the ProvideCodeGeneratorExtensionAttribute to associate the generator with a file extension.
Create a VSIX with your package and generator and have your users install it.

How to generate UIMap.Designer.cs file in visual studio 2010 using UIMap.uitest file?

I'm new guy to using visual studio 2010. I want to generate the UIMap.Designer.cs and UIMap.cs files using the given UIMap.uitest file(which is like .xml file). I tried in so many ways but, i can't. Can i generate those files from UIMap.uitest file using some dll files or any codes are available....? Please guide me.....
Thanks is advance...
Selvam.
From MSDN:
UIMap.Designer.cs
This file contains code that is automatically created by the Coded UI
Test Builder when a test is created. This file is re-created every
time that a test changes, so that it is not a file in which you can
add or modify code.
The same is true for UIMap.cs

Copy Files to Project Folder with Visual Studio Project Template

I'm making a custom Visual Studio Project Template for a CSharp project and was wondering if there was a way to copy a dll from the template zip file to the new project file without including the dll in the project files?
The idea is that the project references the dll, but I just dont want the developers to care about the assembly.
What I did was, created new template wizard i.e. by implementing IWizard interface.
This article(http://msdn.microsoft.com/en-us/magazine/cc188697.aspx) will help you to get started with custom wizard.
Then in the RunStarted() method you will be able to get path to the current template like this
Path.GetDirectoryName((string)customParams[0])
Also you can get the path where the project is created using below code
replacementsDictionary["$destinationdirectory$"]
Once you have these values, do a normal file copy on the RunFinished() method

What type of extension for VS (and how) to make, to generate C# or C++ code from some text [more so a model]?

I am new to Visual Studio Extensibility and want to make an addin/extension which shall do the following:
It should read all the files with a specific file extension (assume "*.ump").
It should process the text/code/whatever in the files.
It should create new Class/Code file with some code in it. [The code will be produced in step 2, just need to know how to do it?]
Yet, I have been racking my brains through extensibility, saw the single file generators .... and addins which go through ProjectItems and can detect the file extension,
BUT I HAVE NOT BEEN ABLE TO FIND a complete tutorial, guide or explanation as to how or what to do!!
Please help...
You don't want to read all files with a specific file extension in Visual C++ project nor standard Visual C# project. You may do that with hand-made MSBuild project (included in the solution).
In Visual C++ projects, there is a way to define custom tools. They are run as separate processes, so you can implement them in anything you want. Studio will ask you whether you want to define a tool (they are defined in special xml files; studio has dialog for editing them) when you add a file with extension unknown to it. In Visual C# projects, just manually write a MSBuild tasks and insert them into the project.
Do whatever you want. IIRC the generated files will have to be included in the project though. Well, for MSBuild, just tweak the project to your heart's desire, but in Visual C++ they have to.
You can combine MSBuild (csproj,vbproj) and VisualC++ projects in a single solution, so I recommend using separate.
If you ever find out you need to compile for different target where you can't use Visual Studio, you'll be glad that you have stand-alone tool you were just calling from Studio and not something that embeds in it.

Resources