1

Read up on it, couldn't find anything that worked for me. Basically, I have a file called SourceCode.vb in my resources. I'm trying to use:

Dim objCodeCompiler As System.CodeDom.Compiler.ICodeCompiler = New VBCodeProvider().CreateCompiler
Dim objCompilerParameters As New System.CodeDom.Compiler.CompilerParameters()
objCompilerParameters.ReferencedAssemblies.Add("System.dll")
objCompilerParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll")
objCompilerParameters.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
objCompilerParameters.ReferencedAssemblies.Add("System.Drawing.dll")
objCompilerParameters.ReferencedAssemblies.Add("System.Data.dll")
objCompilerParameters.ReferencedAssemblies.Add("System.Deployment.dll")
objCompilerParameters.ReferencedAssemblies.Add("System.Xml.dll")
objCompilerParameters.GenerateExecutable = True
objCompilerParameters.GenerateInMemory = False
objCompilerParameters.CompilerOptions = "/target:winexe"
objCompilerParameters.OutputAssembly = "C:\"
Dim strCode As String = My.Resources.SourceCode.ToString
Dim objCompileResults As System.CodeDom.Compiler.CompilerResults = objCodeCompiler.CompileAssemblyFromSource(objCompilerParameters, strCode)
If objCompileResults.Errors.HasErrors Then
    MsgBox("Error: Line>" & objCompileResults.Errors(0).Line.ToString & ", " & objCompileResults.Errors(0).ErrorText)
    Exit Sub
End If

I need it to compile the code and make the file and place it in C:\ - For some reason its not working. Error is:

error: line>0, no input sources specified

Any ideas? Thanks in advance.

Edit: Problem was that I needed to add an actual name for the file after the output. Thanks for the help Hans.

4
  • Are you sure your source code is actually contained in strCode? msdn.microsoft.com/en-us/library/a0kc0z48(v=vs.90).aspx Commented Aug 21, 2015 at 8:21
  • Im 100% sure, just checked. Commented Aug 21, 2015 at 8:28
  • 2
    Well, that's not a fantastic error message. It is actually complaining about your OutputAssembly assignment. You have to specify a file name, not a directory name. Like "c:\test.exe". Which you should not use either, you cannot write to the root directory of the c: drive. Better if you omit it completely, you'll get an assembly in the TEMP directory. Commented Aug 21, 2015 at 8:46
  • Thanks Hans, this worked great! Commented Aug 21, 2015 at 15:28

1 Answer 1

2

It's actually because you are setting OutputAssembly to a location when it expects an assembly name. It should be:

objCompilerParameters.OutputAssembly = "AssemblyName.exe"

If you want to set the location of the output assembly, add it to your compiler options.

objCompilerParameters.CompilerOptions = "/target:winexe /out:C:\\AssemblyName.exe"

Although, I believe if you want to write to the C: drive, you will need to run your program as administrator.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.