Purchase a book of scales from a music store or use a free scale chart online (see Resources). While the theory of building scales is the same regardless of the instrument you play, you might want to consider a scale book specific to your instrument just so you can see the appropriate notation. You'll need to keep a scale theory book handy for easy reference as you go about learning scale structure and how to apply it to your solos. You also want to understand how chords are structured. The note you play over a chord can change the sound of the chord. Playing the seventh note of a C major scale over a C major chord alters the sound to a C7.
Familiarize yourself with the major and minor scale patterns first. Once you understand the step pattern of a scale, it's easy to play it in any key. The steps remain the same in a scale, but the key you're playing in will change, depending upon your starting note. This note is called your root, or home note, and determines the key you're playing in.
Apply the patterns to your instrument so you'll know where to find the notes in any given scale as you build your solos. This is why so many music teachers request you practice your scales.
Determine the key of the song you're going to be writing a solo for. Knowing the key you're playing in tells you what notes are used in the song. If the song is in the key of A, then you know an A major scale will contain notes you can use to build your solo. The key of A major has three sharps: A, B, C-sharp, D, E, F-sharp and G-sharp.
Experiment as you begin putting together your solo. A solo is an individual thing to a certain degree. The way a musician puts a solo together is like a fingerprint. You could stick with only the notes from the scale of the key you're in because you know those notes will go, as long as the chord you're playing over includes those notes. To make it more interesting, a musician will often add notes outside the key. Your ear should tell you whether the note fits or not. There are no hard and fast rules. Use a note if it sounds good to you.