Solved

Include file with application build in VS2010

Posted on 2011-02-24
13
990 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now