Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Include file with application build in VS2010

Posted on 2011-02-24
13
Medium Priority
?
998 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 16

Accepted Solution

by:
13598 earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

647 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