Posts tagged ‘visual_studio’

XNA Game Studio Express is out of Beta

XNA team today released XNA Game Studio Express 1.0 with XNA framework 1.0.

I am working with XNA for a couple of weeks, I will definetely post some samples and give more examples and reference about the framework in later posts.  I really liked that technology and the facilities it provides. Beside that my new project might use XNA, don’t know yet

Migration from ASP.NET 1.1 to ASP.NET 2.0

Although Visual Studio 2005 includes a conversion wizard for old projects, this does not work properly with web applications, because Microsoft removed support for web applications at the beginning. We don’t have a web project, we have a web site. The wizard tries to convert all the files to the new framework. This fails at first compilation, so many errors reported and I don’t want to fix all of these errors, since there exist an easier solution.

ASP.NET team stepped back and gave support for web projects through an add-in for Visual Studio 2005. Visual Studio 2005 Web Application Projects is the easiest way to migrate from ASP.NET 1.1 to ASP.NET 2.0. Because we are able to open our project file, visual studio converts only the project file. So all the files in ASP.NET 1.1 stays and only the project file changes. This is also useful because my code under source control doesn’t have to change.

However in Windows Vista, you don’t have the administrator rights by default and the installation of WAP fails. The solution to that problem is already defined here. The process is simply to write a bat file and run the bat file with administrator rights.

msiexec /i WebApplicationProjectSetup.msi

Another hidden .Net Tool usage basics: ilMerge

Ilmerge is a great utility for any .net developer. What it does is basically merge the assemblies. Let’s say you have three dll and one exe file, you can just merge those 4 files to 1 file using ilmerge. 
As a matter of fact, it is easy to use, you don’t need any recompilation or any other modification. You don’t need to provide installers since there is only one file.

Ilmerge exists in two versions one for .Net 1.1 and the other is .Net 2.0

Basic Usage

Usage: ilmerge [/lib:directory]* [/log[:filename]] [/keyfile:filename [/delaysig
n]] [/internalize[:filename]] [/t[arget]:(library|exe|winexe)] [/closed] [/ndebu
g] [/ver:version] [/copyattrs [/allowMultiple]] [/xmldocs] [/attr:filename] [/pu
blickeytokens] [/wildcards] [/zeroPeKind] [/allowDup:type]* /out:filename <prima
ry assembly> [<other assemblies>...]

Although the help explains very well, here is the usage.

C:\Program Files\Default Company Name\ILMergeBinaryDistribution7>Ilmerge /t:exe
/out:outputfile.exe file1.exe file2.dll

/t us used for the output of the file, exe is for a console application, winexe is for windows forms application and library is for the dlls.

/out is for the name of the output file.

the last parameters are the assemblies to be compined. Attention here is that the first one should be the exe one instead of the class library, becuase it merges the following files to the first file.

Advanced Usage

ILmerge is also usable as a class library for your project. What you need to do is to add the ilmerge executable as a reference and use the namespace of it to do some tasks. The class library is very similar to the console commands.

XML Class Generator for C# using XSD for deserialization

Let’s say we have an XML file and we want to deserialize that file to our implemented class. This is an easy task if the XML file is simple. However if it has more complex types, it can take a long time to implement the class without error. XSD comes with .Net framework SDK. I does not have a user interface, we can access it from the command line tools.

  1. We start it from Visual Studio 2005 -> Visual Studio Tools -> Visual Studio Command Prompt .
  2. Next we need to have a valid XML file that I want to generate the class from. I just use for this sample, the xml output of the yahoo search REST query. Just dowload the xml output of the query
    Yahoo Search xml+class+generator or any other xml file that you want to generate the class from. We save the file as xml.
  3. We use the command xsd to the xml file to generate the xsd schema file.
  4. D:\\test>xsd webSearch.xml
    Microsoft (R) Xml Schemas/DataTypes support utility
    [Microsoft (R) .NET Framework, Version 2.0.50727.42]
    Copyright (C) Microsoft Corporation. All rights reserved.
    Writing file ‘D:\\test\\webSearch.xsd’.
    D:\\test>

  5. Next we use the generated xsd file to generate our class. The generated xsd can contain multiple class, so it would be better to use /classes switch. The default language is C#; however you might want to use it in your Visual Basic Project, to do that just add the switch /language:vb
  6. D:\\test>xsd webSearch.xsd /CLASSES /language:vb
    Microsoft (R) Xml Schemas/DataTypes support utility
    [Microsoft (R) .NET Framework, Version 2.0.50727.42]
    Copyright (C) Microsoft Corporation. All rights reserved.
    Writing file ‘D:\\test\\webSearch.vb’.
    D:\\test>xsd webSearch.xsd /CLASSES
    Microsoft (R) Xml Schemas/DataTypes support utility
    [Microsoft (R) .NET Framework, Version 2.0.50727.42]
    Copyright (C) Microsoft Corporation. All rights reserved.
    Writing file ‘D:\\test\\webSearch.cs’.

  7. Now we have the class file that we use to deserialize the xml object without any exception. So I add the XML file and the generated cs file to my project.
  8. using System;
    using System.Collections.Generic;
    using System.Text;
     
    namespace XSDTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.IO.StreamReader str = new System.IO.StreamReader("webSearch.xml");
                System.Xml.Serialization.XmlSerializer xSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ResultSet));
                ResultSet res = (ResultSet) xSerializer.Deserialize(str);
                foreach (ResultSetResult r in res.Result)
                {
                    Console.WriteLine(r.Title);
                    Console.WriteLine(r.Summary);
                    Console.WriteLine();
                }
                str.Close();
     
                Console.ReadLine();
            }
        }
    }

  9. Here is the output :
  10. XML Class Generator for C++
    Oracle9i XML Developer’s Kits Guide – XDK. Release 2 (9.2) Part Number A96621-01
    . 19. XML Class Generator for C++ This chapter contains the following sections:
    Accessing XML C++ Class Generator … Accessing XML C++ Class Generator. The XML
    C++ Class Generator is provided with Oracle9i and is also available for XML Class Generator for Java
    Oracle9i XML Developer’s Kits Guide – XDK. Release 2 (9.2) Part Number A96621-01
    . 7. XML Class Generator for Java. This chapter contains the following sections:
    Accessing XML Class Generator for Java … The Oracle XML Class Generator for Java is provided with Oracle9i’s XDK for Java …

As you may see this is the easiest and exceptionless solution for using xml output of some web services. What we simply do is generate the classfile, deserialize the xml file to our class and use it.

Download

.

Execute batch commands before or after compilation using Pre-build or Post-build events

Have you ever wanted to execute a set of commands before or after the compilation, like copying the contents of the directory to the target compilation directory, or copy output of the compilation to a specified folder. This feature is integrated inside visual studio with the name; “Pre-build or Post-build event command line”. You access it from the project properties, in the build events tab.

ProjectProperties

If you want to do something before the compilation you enter the shell commands to pre-build, and post-build is the operations for after the compilation. We can use the predefined macros without hard copying the directory names. The edit window will guide us to find the macros.

Editing

Let’s say we want to copy the contents of the output directory to the root d:\. What we do is to edit the post-build event command with the command :

copy /D $(TargetPath) c:\

When we build it. We just get the error, “The command “copy D:\DEV\_Projects\sampleProj\bin\sample.dll d:\” exited with code 1.” Trying to execute the code from command line you get a similar error ‘The system cannot find the file specified.’

copy D:\\DEV\\_Projects\\sampleProj\\bin\\sample.dll d:"
The system cannot find the file specified.


What we forget is the need for the quotations for the long directory and filenames.

copy /D \"$(TargetPath)\" "c:\"

As a result, we can do whatever bat file operations before or after the compilation.