Solved

Include file with application build in VS2010

Posted on 2011-02-24
13
993 Views
Last Modified: 2013-11-26
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
Comment
Question by:DrDamnit
  • 8
  • 4
13 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 34971910
add the file to the program resources
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 34971943
and how do I do that?
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 34971987
Do I need to set build action ? copy to output?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 16

Accepted Solution

by:
13598 earned 500 total points
ID: 34972014
Make sure file is set to include and set the build action to copy
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 34972048
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
 
LVL 16

Expert Comment

by:13598
ID: 34972059
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
 
LVL 32

Author Comment

by:DrDamnit
ID: 34972165
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
 
LVL 32

Author Comment

by:DrDamnit
ID: 34972219
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
 
LVL 16

Expert Comment

by:13598
ID: 34972229
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
 
LVL 32

Author Comment

by:DrDamnit
ID: 34972274
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
 
LVL 16

Expert Comment

by:13598
ID: 34972282
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
 
LVL 32

Author Comment

by:DrDamnit
ID: 34972332
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
 
LVL 32

Author Closing Comment

by:DrDamnit
ID: 34972341
Led to to the right solution! Future users, read entire PAQ.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question