C# Templates for Visual Studio 2005 - c#

I'm looking for some template examples, such as a C# windows dialog.
Do many hackers take advantage of template files?
There are times when I'm creating dialog forms that are very similar. I want to make all my forms look and behave consistently, without doing a lot of coping and pasting.
Add New Item -> My Templates

Here's an article on creating your own Project and Project Item templates:
Create Reusable Project And Item Templates For Your Development Team
Much cooler, but not exactly what you asked for is T4 (text template transformation toolkit) that allow you to do intelligent code generation during builds. Take a look at this MSDN article for more info:
Generating Artifacts By Using Text Templates

Make the template yourself, from the first dialog you made. This will avoid the problem of having to search for a template that does exactly what you want.

There are lots of C# code snippets around. They will provide scaffolding for different structures (properties, dispose pattern and more).
Here is one source.

Related

Code generate new C# project

At the moment I am using C# T4 code generation, but as much as I know it is limited to a class file or other file type generation. I need to generate multiple projects in one solution is it possible to accomplish with T4 templates or there is other technique do to this?
Templates in Visual Studio allow for multiple projects / files templates so you can definitely create this.
The way to create them is simply to setup the skeleton you need for the project, then replace the content of the files in the directory with specific values that will be replaced when the template has the information needed.
I had similar experience.
I developed a whole set of T4 templates to generate a solution. But once you want change code in multiple files, some code may mess up.
So I wrote a code generator based on database schema to generate a VS solution with DAL(Linq To SQL, Entity Framework), BLL, WCF, and UI Applications MVC, WPF, Windows PHone, Windows App Store, Silverlight.
You can goto https://github.com/ntierontime/Log4Net to see whether it meets your architecture requirements, or not. And send me an email with the .dbml(Linq To Sql Classes).

C# Forms App Localization

I have modified my question after the comment which refers to article.
I have a c# Win forms app which contains some forms and dialog boxes/message boxes for user interaction.
I want to localize it to a set of languages.
Most forms are created through the forms designer and the text/strings are set via the properties
Strings for message boxes and other runtime messages come from the code.
I have read the article here
http://msdn.microsoft.com/en-us/library/y99d1cd3(v=vs.71).aspx
Which points to 2 approaches,
First is to have Visual Studio create resouece files for you - this is done for forms designer gernerated code
The second is to manually add resource files and access them code using GetString("strMessage") method
The problem I have in my mind is for desingner generated code I have to use first approch in which VS will create resource files by itself.
To localize my run time messages and mssage boxes I have to use the second approach which means I have to manually add resource files.
I will end up in two sets of resources files for each language. Can I not use just one method and have both form of strings localized in one place ?
Thanks,
Unfortunately you can't (easily) have your cake and eat it too. It's just how MSFT designed things. You can't add message strings to the code-behind ".resx" files generated by the VS forms designer since those ".resx" files will be re-generated by VS any time you make changes to them (overwriting your message strings). VS even warns you about this if you try to add your own resources to these files (using the ".resx" editor in VS). And the converse isn't true either, i.e., you can't add the code-behind ".resx" resources to your manually created ".resx" files (without enormous difficulties). The situation really isn't that bad though. It's been done for years this way and it works. While I would personally prefer a central repository for all resources, every system has its pros and cons. BTW, you should use "strongly typed" resources for your message strings and any other resources in your ".resx" files (the ones you manually add yourself). Don't use "GetString()" IOW (or whatever other function you might find). Strongly typed resources are much easier. Google for the details and after learning how to use them (not hard), also search for the Strongly Typed Resource Generator by Dmytro Kryvko (a very useful tool for VS that improves things even more).
There is nothing stopping you using a combination of both techniques. Go through step 1 to create all of the language resource files, and then add your own strings to those files.

How do I serialize a .NET control to CODE?

I want to create a .NET Form at runtime, add buttons and other controls to that (also at runtime), and then be able to generate a something.designer.cs file from that form (which can then be added to a C# solution and compiled).
What I want to do is very similar to what the WinForm designer does. But instead of having a drag/drop interface for the user, I want to dynamically build the Form/Controls myself at runtime.
I was thinking I could just reuse what the WinForm designer is doing.
Is that possible?
This MSDN magazine article should have everything you need.
It's really not as simple as it was pre-.NET as the visual version of the form you see in Visual Studio is actually the result of multiple files.
But in the simplest form you could simply just mirror what .NET does at the start of creating a new form:
Create three files Form.cs, Form.Designer.cs and Form.resx (which is an XML file).
Place the same default content in them that VS does
Mimic the code generated when adding controls, code-behind and resources
It will be a tedious task, but it can be done. Adding resources however will be burdensome.
Yes, you can do achieve this using Compiler Services (compiling c# code) or Emit class if you know building correct MSIL.

Which is a good way to maintain resources for Internationalization in .Net

I have thought of three approaches to create and maintain resources in .Net projects for WinForms using Visual Studio 2008. (I am sure there should be more than three ways.) I need to decide on one before starting to implement internationalization for our product.
Have individual sets of resource files (resx) for each windows form or piece of UI (a custom control) in each .net project. These are auto generated by Visual Studio when Localizable property is set to true in the form or control properties.
Have one resource file per .net project. This is added manually and updated manually with the resource strings and messages.
Have one resource manager project that has resources for all the components for a set of .net projects.
Personally, I do not like the first approach as it creates numerous resources files. The only advantage we get in this approach is that we do not need to set text in UI elements manually.
I like second and third approach as they are easy to maintain and there is only one set of resources that you need to handle. So no duplication of strings and messages. Easy for the translators also.
What are your thoughts? Please share.
I have tended to use VS to create the project and provide the default set of resources but then maintain any additional resources outside of visual studio via the SDK tools winres.exe, resgen.exe and al.exe.
You can maintain the resources in a fairly simple folder structure of one folder per culture and just have a batch file or two to build the resources into satellite assemblies. This gives you the advantage of keeping the VS solution to the core product and all localisation can be done after the fact.
If internationalizing your app means more than translating pieces of text you should go with the first one. You can create satellite assemblies to deploy different cultures. This way you are not localizing just text but also images, control layout, etc. This is the way how Microsoft recommends it and they have good reasons for taking this approach.
I've found that the simplest approach to internationalization is to simply maintain a list of all the different pieces of text in your application (labels, buttons, form captions etc.) in a spreadsheet or tab-delimited file of some sort, and then send this file to the translators to add (in one additional column for each language) all the translations.
You then call a simple method in the Load event of each form (which are all maintained in English) that iterates through all the controls on the form recursively and changes their Text properties to the translated values for whichever language you're translating the app into. The language can either be determined programatically (I forget where in the .Net namespace this is indicated), or you can have a simple language selection dialog when the application first starts (the advantage of this second method is that your app can be translated into whatever language the user wishes, without having to set the language for all of Windows - this is especially useful for kiosk applications).
In my opinion, creating and maintaining all the different internationalized versions of every form is a major pain, although it is useful when the translated text values are significantly different in size from the English versions.
Personally, I prefer the first approach because the context (in your case, the forms) is very important for a translator to do his job perfectly. In your second and third approach, the context is gone because it is just a list of strings.
Yes, the first approach can be a pain to maintain but at least your application would be translated correclty.
I personally love to add a single project .Resources.
Next I enable Microsoft MAT ( https://developer.microsoft.com/en-us/windows/develop/multilingual-app-toolkit ) and manage all my translations via MAT.
This way you can also recycle translations from other solutions, saves you time ;-)

Visual Studio 2008 and C#

I'm an IT Professional with a background with developing ASP/VBscript/SQL web applications. I want to take some training and get up to speed with Visual Studio 2008 and C# so that I can take over a project at work and make updates/bug fixes in house rather than calling in a third party.
The web application I'll be working on was developed in Visual Studio 2005 with a mix of C# code and some Ajax.
When I load the source code into Visual Studio 2008 I received a warning that the Source Control Plugin wasn't installed. It's looking for SourceSafe which I don't have. Is this necessary to use?
I'm starting a training course in February called Introduction to Visual Studio C# 2008. Well this be adequate to get me going in the right direction to be able to update, fix, and make minor changes to our web application? This is a big opportunity for me and I don't want to blow it.
Thanks!
SourceSafe is a Software Configuration Management tool from Microsoft, and is not required. I WOULD recommend using some form of SCM, but flavor is a matter of preference.
If the pop-ups are annoying to you and you would like to disable them, then removing the SourceSafe bindings from the project should stop them.
From http://weblogs.asp.net/bkcarroll/archive/2004/03/08/86059.aspx :
Solution:
1 - Go to the folder containing the solution files and delete the following:
mssccprj.scc
MyProject.vssscc
vssver.scc
2 - Open MyProject.sln in your favorite text editor and remove the following section:
GlobalSection(SourceCodeControl) = preSolution
...
EndGlobalSection
3 - Go to the folder containing the project files and delete the following:
MyProject.vbproj.vspscc
mssccprj.scc
vssver.scc
4 - Open MyProject.vbproj in your text editor and remove the following lines:
SccProjectName = "SAK"
SccLocalPath = "SAK"
SccAuxPath = "SAK"
SccProvider = "SAK"
Now you can open the solution/project with no source control errors.
As far as the class goes, if you're already familiar with ASP/VBScript, you can probably pick up a C# class and figure out the rest. If not, I would suggest going for an ASP focused class that utilizes a C# back-end.
I would expect that a course named "Introduction to Visual Studio C# 2008" would probably not cover Ajax technologies, so you might want to look for some additional resources on that topic. (It might not even cover ASP.NET in significant depth, so I'd advise checking the syllabus, and if the ASP.NET coverage is weak then prepare for some additional learning on that topic as well.)
Re the Source Safe plug-in: you will need this if you want to work on the code base (so you can check in and out of the existing VSS repository). You will not need it just to browse the code.
Well James that is up to you. I am not familer with the course but if you apply yourself and pay attention I'm sure you can achive your goal. Do not be afraid to move beyond just course work to learn new things. There is a lot of information about Visual Studio on the internet.
SourceSafe is not required to use Visual Studio.
Learning the basics of VS will definitely allow you to update and fix your web apps. VS allows you to work with all the technologies you mentioned all in one environment. Although ASP/VBScript are "legacy" at this point, there is still support for them in the VS environment.
James I'd suggest that you look at the free resources (video and textual) available to you on ASP.NET. I would presume that once you've read a few tutorials and watched some videos + taken your training course you should be able to maintain the code base. Add in the fact that sites like StackOverflow have a large .NET community and there are always people willing to help.
Good luck

Categories