There are many tools you can use to put together a solo. The more methods you use, the more diverse and varied your solos can be. One of the biggest difficulties in writing a solo is choosing among the huge number of possibilities. As you become more experienced in writing solos, you will be able to see more of these possibilities, as well as narrow them down to find the right one. Often there can be many right answers. You can do slow, lyrical melodies, or fast arpeggios. You can make it sweet and angelic, or aggressive. You can do both within the same solo.
In this article, I won't spend much time describing "pure" or traditional ways of writing solos. You're probably familiar with these methods already. Some of these methods might work better for you than others, depending on the style of music you play and the kind of soloing you like. However, even if you prefer a style of music that relies heavily on traditional, guitaristic playing, you may still get some benefit from these approaches, so read on!
If you have the ability to record on a decent computer setup with a sequencer and the ability to edit and mix your tracks, writing your solos will become much easier. This kind of setup gives you a huge advantage over just writing with a guitar because of the tools at your disposal. If you don't have access to this, you can still use most of these techniques.
Some of you may be skeptical of giving music thought and preparing something in advance. I don't think it's really helpful to say something like "don't worry about it, just play". This works just fine if you're already a great soloist. Otherwise, "just playing" is not going to sound as good as you could sound with some thought and effort. Once you have experience in this kind of thinking, playing great solos should become more and more natural.
If you prefer to keep your solos improvised, you can think of writing a solo as practice for your improvisation. Improvisation is a lot like speaking a language. You have to know the language before you are able to speak it. Think of writing a solo as learning the language.
With A Guitar:
Improvise several times and take the best parts. This is a classic and often used technique. The easiest way to do this is to actually record that improvisation and cut the best parts together. You could do this throughout the process. For example, the first thing you can do when you begin is record some improvisation. Then after using some of the other techniques mentioned later, you can do another round of improvisation. Chances are the new improvisation will be informed by the other techniques you used.
Using Other Instruments:
It's always a good idea to write on another instrument and learn it on your guitar. This opens up new ways of thinking about melody, since you aren't confined to your technique on guitar, or the patterns and scales you know. If you always write on guitar, you tend to get similar results.
I often write my solos without my guitar. Then when I learn them, I play around with the idea and take advantage of the things you can do on guitar like vibrato and string bends. The results aren't as good if you don't do this. For example, if I wrote a solo on piano I would almost always decorate it with some vibrato, slides and bends when I play it on guitar.
You can sing over the music, and learn the melodies on the guitar. Your voice is the most natural way of expressing the ideas in your head. You don't have to actually sing out loud, humming is fine. The ideas you come up with this way will probably fit the music very well, but they probably won't be very complex. People rarely sing like a guitarist plays, with fast scale runs or arpeggios. This method will provide you with very simple, catchy and fitting melodies.
You can use a sequencer to write out ideas and then learn them. Import the music into the sequencer and sync the tempo of the midi to it. Then just write out notes until you find something you like. This is an interesting method to remove the guitar from the situation. The parts you write will often be difficult to play on guitar because they won't be idiomatic to the instrument. This is useful for getting outside your technique and the solos you've already played. You'll probably find yourself learning patterns you've never thought of playing before.
Experiment with these techniques and see what works best for you. Each technique is going to give a distinct kind of result. One of them may be more suited to your individual style than the rest. The easiest way to combine all these techniques is to record the different parts and experiment with arranging them. Try starting on different beats and placing the pieces in a different order. Once you've gotten a solo together, learn it all and play it over again so it doesn't sound awkward and cut together.
If you are looking for a backing tracks CD to practice your soloing over, check out Improve Your Improv