Archive for October 2010

Changing the prompt for csh on FreeBSD 8.1

The prompt by default for csh on FreeBSD is simply a sing percent symbol.

%

There is not space before or after this.  I don’t like it and it drives me crazy. I like a prompt to tell me three things:

  1. Who is logged in.
  2. The machine name.
  3. The current path.

This change is quite simple.  It can be made temporarily, permanently for all users, or permanently for a single user.

Temporary

Sometimes you don’t want to make a permanent change to the prompt.  Especially if you are on someone else’s system temporarily and using one of their shells.  In such a case, setting the prompt temporarily is desired.

To see the prompt temporarily, simply run this command:

set prompt = “[%n@%m %c]$ “

Your prompt should now look as follows:

[SomeUser@SomeComputer ~]$

This is only temporary. As soon as you close the shell, the settings is gone and any new shells will continue to have the old setting.

All Users

To make a change for all users, the file that needs to be edited is /etc/csh.cshrc.

By default the file is empty except for some comments.  Line that are comments begin with the # character.

Add these lines to empty file:

if ($?prompt) then
        # An interactive shell -- set some stuff up
        set prompt = "[%n@%m %c]$ "
endif

After making this change, your prompt should look as follows:

[SomeUser@SomeComputer ~]$

If the file is not empty then you probably have to search yourself if the prompt is being set and replace it with the above.

Be careful that the prompt is not set for a single user because if it is, the user’s setting overrides the global settings.

Single User

The prompt can be set on a user by user basis.  The user’s settings will override the global setting.

To make a change for a single user, the file that needs to be edited is ~/csh.cshrc.

By default the file looks as follows:

# .cshrc - csh resource script, read at beginning of execution by each shell
#
# see also csh(1), environ(7).
#

alias h         history 25
alias j         jobs -l
alias la        ls -a
alias lf        ls -FA
alias ll        ls -lA

# A righteous umask
umask 22

set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin)

setenv  EDITOR  vi
setenv  PAGER   more
setenv  BLOCKSIZE       K

if ($?prompt) then
        # An interactive shell -- set some stuff up
        set filec
        set history = 100
        set savehist = 100
        set mail = (/var/mail/$USER)
        if ( $?tcsh ) then
                bindkey "^W" backward-delete-word
                bindkey -k up history-search-backward
                bindkey -k down history-search-forward
        endif
endif

After modification, my /etc/csh.cshrc looks like this:

# $FreeBSD$
#
# .cshrc - csh resource script, read at beginning of execution by each shell
#
# see also csh(1), environ(7).
#

alias h         history 25
alias j         jobs -l
alias la        ls -a
alias lf        ls -FA
alias ll        ls -lA

# A righteous umask
umask 22

set path = (/sbin /bin /usr/sbin /usr/bin /usr/games \
           /usr/local/sbin /usr/local/bin $HOME/bin \
           /usr/local/kde4/bin /usr/local/kde4/sbin \
           /usr/X11R6/kde4/bin /usr/X11R6/kde4/sbin \
           /usr/X11R6/kde4/lib/kde4/libexec)

setenv  EDITOR  vi
setenv  PAGER   more
setenv  BLOCKSIZE       K

if ($?prompt) then
        # An interactive shell -- set some stuff up
        set prompt = "[%n@%m %c]$ "
        set filec
        set history = 100
        set savehist = 100
        set mail = (/var/mail/$USER)
        if ( $?tcsh ) then
                bindkey "^W" backward-delete-word
                bindkey -k up history-search-backward
                bindkey -k down history-search-forward
        endif
endif

Your prompt should now look as follows:

[SomeUser@SomeComputer ~]$

Whatever you set the prompt to as a single user will override the global setting.

What is the equivalent of __FILE__ and __LINE__ in C#?

Where is __LINE__ and __FILE__ in C#?

In C++ and in PHP and other languages, a great logging feature is the ability to log the file and line number where the log occurs.

These unfortunately do not exist.  I have been searching even in the latest .NET 4.0 and haven’t found them.  If they are there, they are hidden. Having these two variables is an extremely useful feature in other languages and it appears to be a feature very overlooked by the C# developers. However, maybe they didn’t overlook it.  Maybe there is a good reason that it is not there.

Getting __LINE__ and __FILE__ in C# when in debugging mode

There were a couple of solutions floating around online but many of them only worked with debugging enabled (or in release if the pdb file is in the same directory).

Here is one example that only works in debugging (or in release if the pdb file is in the same directory).

StackHelper.cs

using System;
using System.Diagnostics;

namespace FileAndLineNumberInCSharpLog
{
    public static class StackHelper
    {

        public static String ReportError(string Message)
        {
            // Get the frame one step up the call tree
            StackFrame CallStack = new StackFrame(1, true);

            // These will now show the file and line number of the ReportError
            string SourceFile = CallStack.GetFileName();
            int SourceLine = CallStack.GetFileLineNumber();

            return "Error: " + Message + "\nFile: " + SourceFile + "\nLine: " + SourceLine.ToString();
        }

        public static int __LINE__
        {
            get
            {
                StackFrame CallStack = new StackFrame(1, true);
                int line = new int();
                line += CallStack.GetFileLineNumber();
                return line;
            }
        }

        public static string __FILE__
        {
            get
            {
                StackFrame CallStack = new StackFrame(1, true);
                string temp = CallStack.GetFileName();
                String file = String.Copy(String.IsNullOrEmpty(temp)?"":temp);
                return String.IsNullOrEmpty(file) ? "": file;
            }
        }
    }
}

Here is a little Program.cs that shows how to use it.

using System;

namespace FileAndLineNumberInCSharpLog
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 100;
            int y = 200;
            int z = x * y;
            Console.WriteLine(StackHelper.ReportError("New Error"));
        }
    }
}

Unfortunately if the above does only work in release if the pdb file is available.

Getting __LINE__ and __FILE__ in C# when in debugging mode

Well, according to this MSDN forum post, it simply cannot be done.
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6a7b021c-ec81-47c5-8f6a-2e280d548f3f

If I ever find a way to do it, I will post it.

So for troubleshooting a production file at a customer’s site, you pretty much have to send out your pdb file to them when they need it.  There are a lot of benefits to C# and this lacking feature is one of the eye sores.

The KDE Network Configuration tool on FreeBSD

I am looking for a Graphical Newtork Configuration tool for FreeBSD. However, my attempts to find one are unsuccessful.

KDE’s “Network Settings” tool

So, KDE on FreeBSD has a network configuration tool.  However, it doesn’t appear to work. PC-BSD has a working network management tool, that looks different.

I don’t have PC-BSD installed, but instead my own desktop build on FreeBSD, so I dont’ have a PC-BSD screen shot, but here is the screen shot from KDE’s regular Network Settings.

It flashes a little box that says, detecting platform and then the screen is empty of network cards.

I am on FreeBSD 8.1 64 bit.

I have these ports installed:

[jared@slc-jab ~]$ pkg_info |grep kde
akonadi-1.4.0_1     Storage server for kdepim
kde4-4.5.2          The “meta-port” for KDE
kde4-icons-oxygen-4.5.2 The Oxygen icon theme for KDE
kde4-shared-mime-info-1.0 Handles shared MIME database under ${KDE_PREFIX}
kde4-xdg-env-1.0    Script which hooks into startkde and helps KDE pick up XDG
kdeaccessibility-4.5.2 Accessibility applications for KDE4
kdeadmin-4.5.2      KDE Admin applications
kdeartwork-4.5.2    KDE Artworks Themes
kdebase-4.5.2       Basic applications for the KDE system
kdebase-runtime-4.5.2 Basic applications for the KDE system
kdebase-workspace-4.5.2 Basic applications for the KDE system
kdebindings-smoke-4.5.2 SMOKE bindings for Qt/KDE
kdeedu-4.5.2        Collection of entertaining, educational programs for KDE
kdegames-4.5.2      Games for the KDE integrated X11 desktop
kdegraphics-4.5.2   Graphics utilities for the KDE4 integrated X11 desktop
kdehier4-1.0.6      Utility port that creates hierarchy of shared KDE4 director
kdelibs-4.5.2       Base set of libraries needed by KDE programs
kdemultimedia-4.5.2 KDE Multimedia applications
kdenetwork-4.5.2    KDE Network applications
kdepim-4.4.6        Libraries for KDE-PIM applications
kdepim-runtime-4.4.6 Libraries for KDE-PIM applications
kdepimlibs-4.5.2    Libraries for KDE-PIM applications
kdeplasma-addons-4.5.2 Extra plasmoids for KDE4
kdesdk-4.5.2        KDE Software Development Kit
kdetoys-4.5.2       Collection of entertaining programs for KDE
kdeutils-4.5.2      Utilities for the KDE4 integrated X11 Desktop
kdeutils-printer-applet-4.5.2 Printer system tray utility for KDE4
kdevelop-4.0.0      Opensource IDE based on KDevPlatform, KDE and Qt libraries
kdevelop-php-1.0.0  PHP support for KDevelop
kdevelop-php-docs-1.0.0 PHP documentation for KDevelop
kdevplatform-1.0.0  KDE development platform
kdewebdev-4.5.2     Comprehensive html/website development environment
py26-kdebindings-kde-4.5.2 Python bindings for KDE
py26-kdebindings-pykdeuic4-4.5.2 An enhanced version of pyuic4
ruby18-kdebindings-4.5.2 Ruby bindings for Qt/KDE
system-config-printer-kde-4.5.2 KDE4 frontend for system-config-printer

So there according to the README in subversion for KDE’s network settings, this is supposed to work on FreeBSD. Maybe it doesn’t actually work.  I can configure my network from the command line, so it doesn’t affect me, it just affects me trying to get new users who don’t know how to configure the network from the command line.

Looks like no one has maintained this feature on the FreeBSD platform and it is not working.

PC-BSD’s “System Network Configuration” tool

PC-BSD has their Network Management tool available as a port it appears. /usr/ports/net/pcbsd-netmanager

However, when I installed it on FreeBSD, it didn’t really work either. Again, I am not on PC-BSD, just my own Xorg and KDE build on FreeBSD. It did work on PC-BSD when I was testing PC-BSD.

When I installed it to FreeBSD, it added a different network configuration option to the KDE System Settings called “System Network Configuration” which is different than the default one called “Network Settings”.

I sort of wish that instead of writing a new tool, the PC-BSD team had just worked with KDE to make the regular one work, but maybe there is a reason I am not aware of that made this a necessity. Anyway, that is besides the point, the GUI network configuration tool from PC-BSD didn’t work when installed to FreeBSD either.

It shows the network devices, physical, wireless, and virtual, but while it displays them, right-clicking and choosing the Configure option does absolutely nothing.

Any one know if GNOME has a GUI Network Configuration?

I didn’t check out GNOME’s options.  I don’t have GNOME installed and installing it is a bigger chore than I was planning on trying for finding a GUI network configuration tool

Conclusion

If you are running PC-BSD, the graphical System Network Configuration tool works.

If you are running FreeBSD, you may be out of luck using your own network configuration tool.

Options

The options seem to be these.

  1. We can contact the folks at PC-BSD and the folks at KDE and see if either have plans to make their tool work.
  2. We could step in and help either PC-BSD or KDE and fixing this ourselves and contributing our code.
  3. Write our own tool.

I like option 1 or 2. I guess I will contact PC-BSD and see what I can do to help.

Virtual Machines, Snapshots, Domain Membership, and trust relationship

Ok, so many of you have reverted to a snapshot of a virtual machine that is a member of an Active Directory domain only to see the error message saying something like this:

In XP:
“Windows cannot connect to the domain, either because the domain controller is down or otherwise unavailable, or because your computer account was not found. Please try again later. If this message continues to appear, contact your system administrator for assistance.”

In Windows 7:
“The trust relationship between this workstation and the primary domain failed.”

This happens whether you are using VMWare or VirtualBox. It also happened back when we were re-imaging to “revert” our drives.

This is caused because the Machine creates an account on the Domain. It actually maintains its own password and updates its own password every 30 days.  So as soon as the Machine account’s password is updated, you are going to be in this state.

Well, I started thinking that there has to be a solution for this. I found this article:
Working with Domain Member Virtual Machines and Snapshots

It mentions a possible option.

“Increase the computer account password age, or disable password changes altogether. Both these can reduce likelihood of the problem, but may reduce the level of security in the domain. On the other side, since this is probably a test, a QA or a demo environment, you may consider it as a valid option . These settings are available on the domain member (and not on the domain controller), and as such, you can change them on your computer before you create a snapshot out of it.”

While he mentions that it can be done, he doesn’t mention how to do it.  There is a Microsoft Knowledge-base article about this.  This is a WIndows 2000 article, but I will have to verify that it works in later versions.
How to disable automatic machine account password changes

It basically says to set this registry key:

KEY: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters
Property: DisablePasswordChange
Value: 1

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Netlogon\Parameters]
"DisablePasswordChange"=dword:00000001

You may be able to do this on the Domain controller, by using this setting:

KEY: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters
Property: RefusePasswordChange
Value: 1

Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters]
"RefusePasswordChange"=dword:00000001

So I am going to try the first one, as it doesn’t require a global setting on the domain.  Lets see if it really works.

Update

I put the first registry key on all my VMs back when this was posted, which looks like October 22, 2010.  I haven’t had the problem since, so I would say this solution works.

I don’t know if the second key that goes on a Domain Controller works.  Maybe some one can try it out for me.

Installing the NVIDIA driver on FreeBSD 8.1

Ok, so it is one thing to have Xorg just autodetect settings, it is another to install and take advantage of a powerful NVIDIA driver and all its features.

To install the NVIDIA driver on FreeBSD 8.1, do the following.

  1. This needs to be done as root, so su to root.
  2. Install the NVIDIA driver. (Obviously only do this if your video card is NVIDIA)
    #
    #
    cd /usr/ports/x11/nvidia-driver
    make install

    Note: You will be prompted for the build configuration. Check the ACPI box because I suspect ACPI is needed if you want to sleep and resume. If you have Linux compatibility enabled or plan to use it later, leave that checked, otherwise uncheck it and hit ok.

  3. Edit the /boot/loader.conf file.
    # ee /boot/loader.conf
  4. Add the following line to configure the NVIDIA module to load at startup.
    nvidia_load=”YES”
  5. Install the NVIDIA configuration tool.
    #
    #
    cd /usr/ports/x11/nvidia-xconfig
    make install
  6. Use Xorg to create an xorg.conf. The following command creates and xorg.conf.new in /root.  This might detect the NVIDIA driver, or not. Whether it detects it or not if may not make all the desired settings.  The nvidia-xconfig tool will make the xorg.conf file settings work more accurately for the NVIDIA driver.
    # Xorg -configure
  7. Copy the file to the appropriate location
    # cp /root/xorg.conf.new /etc/X11/xorg.conf
  8. Run nvidia-xconfig
    # nvidia-xconfig
  9. Edit the /etc/X11/xorg.conf.
    # ee /etc/X11/xorg.conf
  10. Add this line in the driver section or “Section Device” to enable transparancy.
    Option Overlay

Ok, you should have your NVIDIA card working. There are probably many more tweaks you could make. If you know of any other options that your would recommend, please comment and let my readers and I know.

Tutorial – Binding to Resources.resx for strings in a WPF Application: A technique to prepare for localization

Update: This is no longer a recommended way to do localization in WPF.
Use this project from NuGET: WPFSharp.Globalizer
Also read this post: How to change language at run-time in WPF with loadable Resource Dictionaries and DynamicResource Binding

Introduction

Ok, so if you are going to have a string visible in your WPF application and your application can be in multiple languages, you are facing the localization problem.

Usually people as themselves two questions:

  • Do I localize or not?
  • How do I localize?

The answers are usually not now and I don’t know. So no localization work is done at first. Later, you wish you were more prepared for localization.

Well, I am here to tell you that you can at least prepare to be localized by doing a few simple steps:

  1. Centralize your strings in a publicized Resources.resx file.
  2. Add a reference to your Properties.
  3. Replacing any statically entered text with the name of the string resource.
  4. Do you best to use dynamic sizing.

Preparing your strings for localization

If you are going to have a string in your WPF application, it is a good idea to store those strings in a centralized place for localization purposes. Usually in Visual Studio, that is in Resources.resx.

Cialis is an additional impotence problems treatment, http://www.horizonhealthcareinc.com/ which is gaining interest at a faster pace. The reason for more popular at a faster pace is because of its effectiveness.

Often a string is entered directly into an the WPF XAML. This is not recommended. Maybe you are thinking that you don’t need to localize your application, so this is not important to you. Ok, really what you are thinking is:

“I don’t know how to do it and if I ever get big enough to need localization, at that point, I will figure it out.”

Well, what if I told you that using Resources.resx is extremely easy?

What if I told you that it hardly takes more time at all?

If it easy and hardly time consuming at all, you would do it, right? I would. Hence this post.

Step by step guide for Preparing your strings for locaization

I have a project called LicenseAgreementManager. Right now this only needs to display a license agreement in English, but maybe someday, this will need to display a license agreement in any language.

Preparation – Create a new project or use an existing project

In Visual Studio, create a new WPF Applcation project.

I named my project LicenseAgreementManager.

Right away, you already have at least one string statically entered into your XAML, the text for the window title.

Step 1 – Add all your strings to the Resources.resx file

  1. Double-click on Resources.resx in your WPF Project. This found under the ProjectName | Properties option in your Solution Explorer tree.
  2. Change the Access Modifier drop down menu from Internal to Public.
  3. Enter your strings in the Resources.resx by giving them a unique name and a value of the desired string. A comment is also optional.

You now have a publicized Resource.resx file and a few strings inside it.

Step 2 – Add a reference to your Properties

  1. In your project, open your MainWindow.xaml file.The XAML looks as follows:
    <Window x:Class="LicenseAgreementManager.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
    
        </Grid>
    </Window>
    
  2. Add a line to reference your Properties in the Windows element.
    <Window x:Class="LicenseAgreementManager.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:p="clr-namespace:LicenseAgreementManager.Properties"
            Title="MainWindow" Height="350" Width="525">
    

Step 3 – Replace static text with strings from the Resources.resx

  1. Change the Title attribute from static text to instead use access the string from your Resources.resx named EULA_Title.
    <Window x:Class="LicenseAgreementManager.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:p="clr-namespace:LicenseAgreementManager.Properties"
            Title="{x:Static p:Resources.EULA_Title}"
            Height="350" Width="525">
    

That was pretty easy, wasn’t it.

As you add elements that have strings, use the Resources.resx.

Step 4 – Try to use dynamic sizing

  1. As best as possible, remove any dynamic sizing.I have just added some items and removed the sizing as best as possible. Here is my XAML.
    <Window x:Class="LicenseAgreementManager.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:p="clr-namespace:LicenseAgreementManager.Properties"
            Title="{x:Static p:Resources.EULA_Title}"
            SizeToContent="WidthAndHeight"
            xml:lang="en-US">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
    
            <RichTextBox Name="_EulaTextBox" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"/>
            <StackPanel Grid.Row="1" Margin="0,10,0,0" Name="stackPanel2" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch">
                <RadioButton Content="{x:Static p:Resources.EULA_Accept}" Margin="20,20,20,0" Name="radioButton1" />
                <RadioButton Content="{x:Static p:Resources.EULA_NotAccept}" Margin="20,20,20,0" Name="radioButton2" />
                <Button Content="{x:Static p:Resources.Next_Button}" Name="button1" Margin="20,20,35,20"  HorizontalAlignment="Right" />
            </StackPanel>
        </Grid>
    </Window>
    
  2. What changes did I make above that I couldn’t do through the Visual Studio GUI?
    1. I removed Height and size from almost every element.
    2. I added SizeToContent=”WidthAndHeight” to the Windows element.
    3. I added some extra size to the margins.

Conclusion

You don’t have to be localized to be prepared for easy localization. By doing the above simple steps, when it comes time to add localization, you will be ready.

If you want to go on an finish localization. You might want to read some of my sources.

Sources:

http://compositeextensions.codeplex.com/Thread/View.aspx?ThreadId=52910
http://msdn.microsoft.com/en-us/library/ms788718%28v=VS.90%29.aspx
http://msdn.microsoft.com/en-us/library/ms746621.aspx


Copyright ® Rhyous.com – Linking to this article is allowed without permission and as many as ten lines of this article can be used along with this link. Any other use of this article is allowed only by permission of Rhyous.com.

Adding an alias in Windows 7 or making ls = dir in a command prompt

Hey all,

I don’t know about you but I switch between FreeBSD and Windows a lot.  So it drives me crazy when I type the command ls on windows and get the error message.

C:\Windows\system32>ls
‘ls’ is not recognized as an internal or external command,
operable program or batch file.

So I want this to go away.

I looked for the alias command in Windows and couldn’t find one.  So I made a batch file that solves this.

Windows doesn’t seem to have the equivalent of a .shrc or .cshrc or .bashrc. I couldn’t find a .profile either.  So I decided to go with the batch file route.

Option 1 – Using doskey

I was tipped off to this idea from a comment, which led my mind to the Command Prompt autorun registry I already knew about. But once I wrote the batch file, the parameters were not working, so I searched around and found an example of exactly what I wanted to do here:
http://bork.hampshire.edu/~alan/code/UnixInWin2K/

  1. Create a batch file called autorun.bat and put it in your home directory:
    My home dir is: c:\users\jared
  2. Add the following to your autorun.bat.
    @ECHO OFF
    doskey ls=dir /b $*
    doskey ll=dir $*
    doskey cat=type $*
    doskey ..=cd..
    doskey grep=find "$1" $2
    doskey mv=ren $*
    doskey rm=del $*
    
  3. Add the following key to the registry:
    Key:  HKEY_CURRENT_USER\Software\Microsoft\Command Processor
    REG_SZ  (String): Autorun
    Value:  %USERPROFILE%\autorun.batOr as a .reg file:

    Windows Registry Editor Version 5.00
    
    [HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
    "Autorun"="%USERPROFILE%\\autorun.bat"
    

Now whenever you open a command prompt, the aliases will be there.

Option 2 – Creating a batch file as an alias

I created an.bat file that just forwards calls the original file and forwards all parameters passed when making the call.

Here is how it works.

Create a file called ls.bat. Add the following text.

ls.bat

@ECHO OFF
dir $*

Copy this batch file to your C:\Windows\System32 directory. Now you can type in ls on a windows box at the command prompt and it works.

How does this work to make your aliased command?

  1. Name the batch file the name of the alias.  I want to alias ls to dir, so my batch file is named ls.bat.
  2. In the batch file, set the RealCMDPath variable to the proper value, in my case it is dir.

So if you want to alias cp to copy, you do this:

  1. Copy the file and name it cp.bat.
  2. Edit the file and set this line:
    SET RealCMDPath=dir

Now you have an alias for both ls and cp.

Using different versions of msbuild.exe

You can also use this so you don’t have to add a path.

I need to use C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe but sometimes I want to use C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe. Both files are named the same. So I can easily use my alias command.

  1. Create two files in C:\Windows\System32: one named msbuild35.bat and one named msbuild40.bat.
  2. Change the line in each file to have the appropriate paths for the RealCMDPath.

Anyway, this is really a useful batch file.

WIX: Creating an MSI to deploy multiple files

In this example we are going to create a simple MSI that deploys a two files.  This is not that much different than one file, but there is an implementation decision you have to make here that is important to understand.

Prequisites

Step 1 – Create a WIX project in Visual Studio

Creating a new project is a very simple task once you have done it a few times. However, I try to make my walk-thrus newbie proof, so even some one who has never done this feels comfortable. So if you need help with this step, use my instructions below. If you don’t, skip them.

  1. Open Visual Studio if it is not already open.
  2. Got to File | New | Project.
  3. You should have an option under Installed Templates for Windows Install XML. Select it.
  4. Now you should see the option for Setup Project. Select it.
  5. Enter a Name for the project. I called the project I made for this walk-thru MultiFileProject.
  6. Change the directory to store the project if you want. It doesn’t matter what directory you choose, but it is nice to keep your learning projects organized.
  7. Click OK.

Your project should now be created. In solution explorer you should now have a solution, a project, a reference and the Product.wxs. See the image below.

Ok, I hope that was easy for you. Lets move on.

Step 2 – Add two files to the project

These steps are preformed in Visual Studio on the project you just created in the above step.

  1. Right-click on the project name, MultiFileProject, and from the drop down, choose Add | New Item.
  2. Select Text File.
  3. Name it whatever you want. I used the default value, TextFile1.txt for this example.
  4. Click Add.
  5. Repeat the steps above to create a second file. My second file is TextFile2.txt.

Your files are now added to the Visual Studio project. However, they are not automatically added into the Product.wxs as a file to be installed. This is done manually in the next step.

Step 3 – Take a moment to learn

We are going to change the Product.wxs file to include the file we just created.

The Product.wxs file has the following XML text in it. Take a moment to look at the XML nodes and their elements so are familiar with the syntax it is using.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
	<Product Id="9a19f6ed-a7b2-4cfc-a429-7069066fbf2a" Name="MultiFileProject" Language="1033" Version="1.0.0.0" Manufacturer="MultiFileProject" UpgradeCode="c1bdcc4d-b249-4b36-97fd-32609a60f8b4">
		<Package InstallerVersion="200" Compressed="yes" />

		<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

		<Directory Id="TARGETDIR" Name="SourceDir">
			<Directory Id="ProgramFilesFolder">
				<Directory Id="INSTALLLOCATION" Name="MultiFileProject">
					<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
					<!-- <Component Id="ProductComponent" Guid="6263db4e-4c67-4adc-9ef1-e1caef798331"> -->
						<!-- TODO: Insert files, registry keys, and other resources here. -->
					<!-- </Component> -->
				</Directory>
			</Directory>
		</Directory>

		<Feature Id="ProductFeature" Title="MultiFileProject" Level="1">
			<!-- TODO: Remove the comments around this ComponentRef element and the Component above in order to add resources to this installer. -->
			<!-- <ComponentRef Id="ProductComponent" /> -->

			<!-- Note: The following ComponentGroupRef is required to pull in generated authoring from project references. -->
			<ComponentGroupRef Id="Product.Generated" />
		</Feature>
	</Product>
</Wix>

The text of the Xml gives us hints as to what we are supposed to do in its comments. Take a moment and read the comments.

Step 4 – Configure the WIX Xml file to deploy that file

Lets start editing that XML file.

Note: I am going to use the term “node’ to indicate and XML section. So and everything it contains is a node. If a node is inside it, I might call it a subnode.

  1. Uncomment the Component node the Directory nodes.
  2. Remove the two TODO: comments.
  3. Uncomment the ComponentRef node that is inside the Feature node.
  4. Remove the TODO: comment and the Note comment.
  5. Inside the Component node, at two File nodes for each of your two files as follows:
    <File Id='TextFile1.txt_id' Name='TextFile1.txt' Source='TextFile1.txt' KeyPath='yes' />
    <File Id='TextFile2.txt_id' Name='TextFile2.txt' Source='TextFile2.txt' />
    

    Notice that the second line is not marked with the KeyPath attribute. Only one file node (or maybe a registry node) can set KeyPath.

Ok, you are done.  Yes, that was all there is too it.   Feel free to add as many files as you want.

You XML syntax should now look as follows:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="9a19f6ed-a7b2-4cfc-a429-7069066fbf2a" Name="MultiFileProject" Language="1033" Version="1.0.0.0" Manufacturer="MultiFileProject" UpgradeCode="c1bdcc4d-b249-4b36-97fd-32609a60f8b4">
    <Package InstallerVersion="200" Compressed="yes" />

    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLLOCATION" Name="MultiFileProject">
          <Component Id="ProductComponent" Guid="6263db4e-4c67-4adc-9ef1-e1caef798331">
            <File Id='TextFile1.txt_id' Name='TextFile1.txt' Source='TextFile1.txt' KeyPath='yes' />
            <File Id='TextFile2.txt_id' Name='TextFile2.txt' Source='TextFile2.txt' />
          </Component>
        </Directory>
      </Directory>
    </Directory>

    <Feature Id="ProductFeature" Title="MultiFileProject" Level="1">
      <ComponentRef Id="ProductComponent" />
      <ComponentGroupRef Id="Product.Generated" />
    </Feature>
  </Product>
</Wix>

Ok, you are ready to build.

Step 4 – Build the project

Well, there really isn’t much to debug, so we are only going to build a release version here.

  1. In the Visual Studio 2010 tool bar, there should be a drop down box that either says Debug or Release. Change it to Release if it is not already at Release.
  2. Select Build | Build Solution or use the shortcut key.

You should now have an MSI built in the project’s bin\release directory.

Step 5 – Test the MSI

Let’s go get the MSI and test it.

  1. Right-click on the project, MultiFileProject, and choose, Open Folder in Windows Explorer.
  2. In Explorer, navigate into the bin\release directory.
  3. You will see two files:
    MultiFileProject.msi – This is the MSI and is all you need.
    MultiFileProject.wixpdb – This is a file for debugging only. You may never use it unless you need to debug.
  4. You may or may not want to test the MSI on you development box. If you do, just double-click the MSI. Otherwise, copy it to a test box and run the MSI there.
  5. Verify that the file installed.
    Note: If on a 64 bit system, it will by default install as an x86 app, so look in c:\program files (x86)\ for a folder called MultiFileProject.
  6. Check Add / Remove Programs to make sure the install shows up there and that the uninstall works.

Congratulations. You just use WIX to create an MSI that deploys multiple files.

WIX: Creating an MSI and Deploying Your First File

Windows Install XML (WIX) is a nice simple way to create an MSI installation file.  Some of the items it automatically handles, such as registering with Add / Remove Programs, are very nice features.

In this example we are going to create a simple MSI that deploys a single file.

Prequisites

Step 1 – Create a WIX project in Visual Studio

Creating a new project is a very simple task once you have done it a few times.  However, I try to make my walk-thrus newbie proof, so even some one who has never done this feels comfortable. So if you need help with this step, use my instructions below.  If you don’t, skip them.

  1. Open Visual Studio if it is not already open.
  2. Got to File | New | Project.
  3. You should have an option under Installed Templates for Windows Install XML. Select it.
  4. Now you should see the option for Setup Project.  Select it.
  5. Enter a Name for the project. I called the project I made for this walk-thru DeployOneFile.
  6. Change the directory to store the project if you want.  It doesn’t matter what directory you choose, but it is nice to keep your learning projects organized.
  7. Click OK.

Your project should now be created.  In solution explorer you should now have a solution, a project, a reference and the Product.wxs.  See the image below.

Ok, I hope that was easy for you.  Let move on.

Step 2 – Add a file to the project

These steps are preformed in Visual Studio on the project you just created in the above step.

  1. Right-click on the project name, DeployOneFile, and from the drop down, choose Add | New Item.
  2. Select Text File.
  3. Name it whatever you want. I  used Install.conf for this example.
  4. Click Add.

Your file is now added to the Visual Studio project.  However, it is not automatically added into the Product.wxs as a file to be installed. This is done manually in the next step.

Step 3 – Take a moment to learn

We are going to change the Product.wxs file to include the file we just created.

The Product.wxs file has the following XML text in it.  Take a moment to look at the XML nodes and their elements so are familiar with the syntax it is using.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
	<Product Id="fae97512-4eca-4271-821d-75b7a8861557" Name="DeployOneFile" Language="1033" Version="1.0.0.0" Manufacturer="DeployOneFile" UpgradeCode="fec17f7b-060e-466f-8bd2-7895eb2b92ce">
		<Package InstallerVersion="200" Compressed="yes" />

		<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

		<Directory Id="TARGETDIR" Name="SourceDir">
			<Directory Id="ProgramFilesFolder">
				<Directory Id="INSTALLLOCATION" Name="DeployOneFile">
					<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
					<!-- <Component Id="ProductComponent" Guid="927a42ea-a6df-45f6-ac52-4b979194bc10"> -->
						<!-- TODO: Insert files, registry keys, and other resources here. -->
					<!-- </Component> -->
				</Directory>
			</Directory>
		</Directory>

		<Feature Id="ProductFeature" Title="DeployOneFile" Level="1">
			<!-- TODO: Remove the comments around this ComponentRef element and the Component above in order to add resources to this installer. -->
			<!-- <ComponentRef Id="ProductComponent" /> -->

			<!-- Note: The following ComponentGroupRef is required to pull in generated authoring from project references. -->
			<ComponentGroupRef Id="Product.Generated" />
		</Feature>
	</Product>
</Wix>

The text of the Xml gives us hints as to what we are supposed to do in its comments.  Take a moment and read the comments.

Step 4 – Configure the WIX Xml file to deploy that file

Lets start editing that XML file.

Note: I am going to use the term “node’ to indicate and XML section. So and everything it contains is a node. If a node is inside it, I might call it a subnode.

  1. Uncomment the Component node the Directory nodes.
  2. Remove the two TODO: comments.
  3. Uncomment the ComponentRef node that is inside the Feature node.
  4. Remove the TODO: comment and the Note comment.
  5. Inside the Component node, at a File node as follows:
    <File Id='Install.conf_id' Name='Install.conf' DiskId='1' Source='Install.conf' KeyPath='yes' />
    

Ok, you are done.  Yes, that was all there is too it.

You XML syntax should now look as follows:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="fae97512-4eca-4271-821d-75b7a8861557" Name="DeployOneFile" Language="1033" Version="1.0.0.0" Manufacturer="DeployOneFile" UpgradeCode="fec17f7b-060e-466f-8bd2-7895eb2b92ce">
    <Package InstallerVersion="200" Compressed="yes" />

    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLLOCATION" Name="DeployOneFile">
          <Component Id="ProductComponent" Guid="927a42ea-a6df-45f6-ac52-4b979194bc10">
            <File Id='Install.conf_id' Name='Install.conf' DiskId='1' Source='Install.conf' KeyPath='yes' />
          </Component>
        </Directory>
      </Directory>
    </Directory>

    <Feature Id="ProductFeature" Title="DeployOneFile" Level="1">
      <ComponentRef Id="ProductComponent" />
      <ComponentGroupRef Id="Product.Generated" />
    </Feature>
  </Product>
</Wix>

Ok, you are ready to build.

Step 4 – Build the project

Well, there really isn’t much to debug, so we are only going to build a release version here.

  1. In the Visual Studio 2010 tool bar, there should be a drop down box that either says Debug or Release.  Change it to Release if it is not already at Release.
  2. Select Build | Build Solution or use the shortcut key.

You should now have an MSI built in the project’s bin\release directory.

Step 5 – Test the MSI

Let’s go get the MSI and test it.

  1. Right-click on the project, DeployOneFile, and choose, Open Folder in Windows Explorer.
  2. In Explorer, navigate into the bin\release directory.
  3. You will see two files:
    DeployOneFile.msi – This is the MSI and is all you need.
    DeployOneFile.wixpdb – This is a file for debugging only. You may never use it unless you need to debug.
  4. You may or may not want to test the MSI on you development box. If  you do, just double-click the MSI.  Otherwise, copy it to a test box and run the MSI there.
  5. Verify that the file installed.
    Note: If on a 64 bit system, it will by default install as an x86 app, so look in c:\program files (x86)\ for a folder called DeployOneFile.
  6. Check Add / Remove Programs to make sure the install shows up there and that the uninstall works.

Congratulations. You just use WIX to create and deploy your first MSI.

 

Bonus Information – Learning about Repair

Repairing an installation is an important feature of  to understand.

What you are going to learn here, is that if you delete a file in a component that has the KeyPath=’yes’ tag, the component will reinstall.

  1. Make sure the MSI you just created above is installed. If you uninstalled it doing steps above, reinstall it.
  2. On the machine where you installed the MSI, Browse to the installation directory.My directory is here.
    C:\Program Files (x86)\DeployOneFile
  3. The only file in that directory is the file you installed:
    Install.conf
  4. Delete the Install.conf file.
  5. Still on the machine where you installed the MSI, go to Add / Remove Programs.
  6. Right-click on the DeployOneFile instance and choose Repair.
  7. The file you deleted should be restored.

Ok, so you probably have questions about repair.  This was just a basic introduction.  Hopefully we will learn more about repair as we go on.

BSD Magazine October Issue Released

Hey all,

The BSD Magazine October Issue Released.

This month the title is VPN and BSD.

Remember, it is a free PDF publication.
http://bsdmag.org/magazine/1542-vpn-and-bsd

Configuring sudo on FreeBSD 8.1 and allowing sudo to open GUI applications

The goal is to install sudo and configure it in a way that allows GUI apps to run.

Without proper configuration the following error occurs when trying to run GUI apps:

No protocol specified
No protocol specified
Error: cannot open display: :0.0

To cofigure sudo, follow these steps below.

  1. Install sudo.
    cd /usr/ports/security/sudo
    make install
  2. Configure sudo be editing the /usr/local/etc/sudoers file.
    ee /usr/local/etc/sudoers
  3. Make the following configuration changes.  The first ones make sudo work with GUI apps.
    Defaults env_keep += “HOME”
    Defaults env_keep += “XAPPLRESDIR XFILESEARCHPATH XUSERFILESEARCHPATH”
    Defaults env_keep += “QTDIR KDEDIR”
    Defaults env_keep += “XDG_SESSION_COOKIE”
    root ALL=(ALL) ALL
    %wheel ALL=(ALL) ALL

Running Unit Tests in Visual Studio 2010: DebugTestsInClass

Problem

So, I am trying to run Unit tests in Visual Studio 2010.  However, it isn’t working.

I am getting this message in the status bar.

The key combination (Ctrl + R, Ctrl + C) is bound to command (DebugTestsInClass) which is currently not available.

I do have Visual Studio 2010 Ultimate so I expected everything to be available.

I did a Google and Bing and MSDN search for “DebugTestsInClass” and got a big fat nothing, which is pretty difficult to do these days. (Of course, that won’t happen for the next guy now that I have made this post!)

Anybody know what the DebugTestsInClass is and how to make it available?

Cause

Ok, so I found the issue.  My test project was created a long time ago in Visual Studio 2008 and using MBUnit.

I had changed the test to use no longer use MBUnit, but to use Microsoft.VisualStudio.QualityTools.UnitTestFramework.

I had create a new test project by click Test | New Test.

Then migrate my test classes to the new project.

I was unaware that the test project must be .NET 4, but yes it does.  Creating a new Test project allows me to use my Ctrl + R, Ctrl + C  functionality.

At first, I thought that using .NET 4 might be a problem because everything else we are doing is currently in .NET 3.5.  However, even though we are developing in .NET 3.5 currently, our test projects can be .NET 4 as they only run on dev and build machines.

Resolution

So it looks like multiple steps were required to move my test project from one testing library to another.

  1. Create a new Test project by going to Test | New Test.
  2. Move the classes to the new test project.
  3. Change the class syntax to match the syntax specified by Microsoft.VisualStudio.QualityTools.UnitTestFramework.
  4. Add any references needed.

 

Utah Open Source Conference 2010

Hey all,

The Utah Open Source Conference 2010 was pretty fun.  It was really my first open source conference.  Yes, I have been into open source for 10 years, specifically FreeBSD, but somehow I haven’t really attended the conferences.

I will probably attend conferences more often.

What was there about FreeBSD?

PC-BSD and the folks as iXSystems sent me with some swag.  Howard Logsdon helped me man the GUBUG booth.

There was a great presentation on FreebSD Jails given by Chris Edwards. (http://www.utosc.com/presentation/157/) Supposedly they are going to post a recording of the presentation. Until then, check it here: (http://wiki.zelut.org/doku.php/presentations:freebsd-jails)

Who else was there?

So Novell SUSE brought some nice laptop bags, and they were pretty good.  I have a nice Ogio laptop back pack, so I am giving this laptop bag to my wife.  It is just big enough to fit her 17″ HP laptop.

There was Fedora, Ubuntu, KDE, and GNOME.  There was a boot on XDMC and MythTV.

There was a very cool company there called Fusion-IO.  They have an awesome hard drive, though they are not cheap. 7k for the cheapest drive. But for some companies, it would be worth it.
When is the next Conference?

You can go here to see upcoming events: http://www.freebsd.org/events/events.html

There is the Meet BSD California 2010 conference November 6 and 7th.

To see when the next Utah Open Source Conference is you should go to the site and register so that when the date is announced, you will be informed.

VirtualBox: It seems ready

Ok, so because my work has given me a license to VMWare Workstation, I have never really gone to the trouble of using VirtualBox.

But I really want to move to use FreeBSD (well, PC-BSD) on my laptop but I have to have a Windows 7 box for work.

So I had Windows 7 with PC-BSD in a VMWare Virtual Machine.

However, I am switching that as we speak.

I now have PC-BSD installed as my primary operating system, and Windows 7 in a VirtualBox Virtual Machine.

There are some features we use at LANDesk a lot, such as many snapshots, and PXE booting, and more.  I will test and follow-up on whether this is a good solution for me.

Blogilo: Writing a post using Blogio, a KDE app on PC-BSD

Hey all,

I decided to try a post using Blogio. Supposedly it is a nice tool where I can write my blogs offline, save them locally, and post them when I can.

So lets see how some of the features work.

This is a heading 1

However, after creating heading 1 and then hitting enter, it did not make the next line’s type to Paragraph. I changed it to paragraph and it was still wrong. I had to click Html editor and then click back to the visual editor to make this work.

This is a heading 2

Same problem with heading 2.

Here is a quote

Ending quote was easy. Just hit the quote button again with the mouse.

  1. This is a numbered
  2. list of items
  3. And we will see if it works.

The font size works, except not for headings.

Well, I am going to be using SilverStripe in a few months. I wonder if it will integrate with that.

Update: There was an issue where when I published this, it didn’t show up right away and said it “missed schedule” whatever that means.  I updated it and now shows up.