• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1010
  • Last Modified:

Include file with application build in VS2010

I wrote a small utility app, which requires a file called settings.xml from which it loads settings.

When I publish, the file is not included, so the app doesn't run.

How do I tell VS2010 to include the xml file, and install it in the same directory as the compiled exe?
0
DrDamnit
Asked:
DrDamnit
  • 8
  • 4
1 Solution
 
nepaluzCommented:
add the file to the program resources
0
 
DrDamnitAuthor Commented:
and how do I do that?
0
 
DrDamnitAuthor Commented:
Do I need to set build action ? copy to output?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
13598Commented:
Make sure file is set to include and set the build action to copy
0
 
DrDamnitAuthor Commented:
Build action doesn't have that option. There is a Copy to Output Directory, whcih I have set to Copy Always.

Settings
Build Action options are attached:


2-24-2011-12-16-18-PM.png
0
 
13598Commented:
Your build action is set to Content and your copty to output is set to what will suit you. I have mine to copy if newer.
0
 
DrDamnitAuthor Commented:
I must be INCREDIBLY retarded.... I cannot get it to work.

What am I missing?

(See attachment).
2-24-2011-12-27-43-PM.png
0
 
DrDamnitAuthor Commented:
Found the xml in the published (and then installed) location under roaming (in the virtual store).

It's included, but not in teh same directory as the exe....

I must bemaking it more complicated than necessary....

See attached.
2-24-2011-12-29-57-PM.png
0
 
13598Commented:
Oh sorry. I thought you just added the file as a new item not as a resource. I always just add mine as a file and set the build action to content and have no problem. I don't add them as a resource.
0
 
DrDamnitAuthor Commented:
This is the error I am getting:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.FileNotFoundException: Could not find file 'C:\Users\michael.HIGHPOWEREDHELP.000\AppData\Local\Apps\2.0\DT4Q94QH.KH4\JH3N7YTC.JVX\head..tion_352b6e7cd2d01362_0001.0000_11b252e4b8acd3e5\settings.xml'.
File name: 'C:\Users\michael.HIGHPOWEREDHELP.000\AppData\Local\Apps\2.0\DT4Q94QH.KH4\JH3N7YTC.JVX\head..tion_352b6e7cd2d01362_0001.0000_11b252e4b8acd3e5\settings.xml'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at HeadlinePrepTool.Form1.LoadSettings()
   at HeadlinePrepTool.Form1.Form1_Load(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
HeadlinePrepTool
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/michael.HIGHPOWEREDHELP.000/AppData/Local/Apps/2.0/DT4Q94QH.KH4/JH3N7YTC.JVX/head..tion_352b6e7cd2d01362_0001.0000_11b252e4b8acd3e5/HeadlinePrepTool.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Open in new window

0
 
13598Commented:
I add mine as a file. Set the build action to content and then from code access it like this:
Dim file_name As String = Application.StartupPath() & "/settings.xml"
0
 
DrDamnitAuthor Commented:
Figured it out.

It was being included as a data file, not regular include.

Under Publish > Applicatin Files, I changed it to "include" and it works.

See attached.
2-24-2011-12-39-45-PM.png
0
 
DrDamnitAuthor Commented:
Led to to the right solution! Future users, read entire PAQ.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now