Solved

Include file with application build in VS2010

Posted on 2011-02-24
13
995 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 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