Reading/Parsing config file in VS2010 C++ - visual-studio-2010

I am working on VS2010 C++/ clr project. I need to initialize some variables which are part of C++ code ( just for clarification , not of C++/CLI code ). Temporarily I have created config.txt file and reading values from that file. It's working file.
But I want some safer/well-tested library for reading/parsing config files.Can anyone point me to right direction in this.

We use Boost.PropertyTree in our project. PropertyTree can read different kinds of config files, e.g. ini, xml or json.
This tutorial may help for a start.

Related

Configuring ANTLR target output location with VS2010

I am new to ANTLR. I wanted to learning start by setting up a project so that lexers\parsers would be automatically generated by the build. So I downloaded antlr-dotnet-tool package, modified a project file to include antlr targets. I also installed some VS extension that add syntax highlighting and new item types for grammar files.
Now, generation seems to works, but it puts output files into obj/${Configuration} folder. And I don't really know what I am supposed to do with them there. Surely, you don't want me to manually copy them to proper locations (supposedly next to grammar files), do you?
It would be great if you could shed some light on it.
If you followed my blog post, you will see that you need to do nothing else,
http://www.lextm.com/2012/07/how-to-use-antlr-on-net-part-v/ (note that at the beginning you will see links to the previous 4 parts)
At compile time the generated files are automatically linked to the output assembly, and the debugger is capable of loading them when you debug the program.

How do I modify the template that reference.cs is generated from?

I've been searching on the web for this, and maybe I'm just using the wrong keywords or something? I could use some help.
My problem is simple - we have a bunch of reference.cs files in our solution, which were auto-generated by VS2010 when adding services. These files don't add XML comments by default, so when we build the project, I get 800 or so messages in the build list. This doesn't break anything, but it does make the build take (significantly) longer, and mucks up the output screen.
I "fixed" this by adding the appropriate #pragma statments to the beginning and end of each reference.cs file, but if those ever get regenerated, they will have to be re-added by hand. I'd like to streamline that process and just add them to whatever T4 template VS2010 is using in the first place. The problem is, I don't know where that is, or if VS2010 is using something else to build these files?
Can this be done? Is there a better solution? I don't necessarily want to turn off XML comments for the entire project.
Visual Studio does not use T4 templates to generate the service reference proxy classes (Reference.cs). Instead Visual Studio is most likely using the WsdlImporter and ServiceContractGenerator classes to generate this code.
There is a stackoverflow post on using either a custom wsdl exporter or WCFExtras to add xml comments to the generated code. Both of these assume you have access to the code for the services you are referencing.

How to variables from a textfile into a C# script

I need to create a text file for a game designer to edit variables in my C# script. I would like to be able to write the variable in the text file and the designer can put in a value and hten it would change in my script.
However, after much searching I have not been able to find a solution to my problem and was hoping someone with some experience in this method could help me.
I'm using Visual Studio for writing my scripts and the designer would require Notepad.
Thanks,
Chris
You can try using this class that will allow you to use ini files to hold your configuration.
I'm assuming your designer wouldn't like to use XML (which is the .NETy way of doing things); making humans edit XML is a form of torture anyway.
Here's the link to the CodeProject page: An INI file handling class using C#.
You can also use some other (relatively simple) format like JSON if ini files are too flat for you.

Intellisense in custom xml file

I have created a custom xml file which I use as a config for my application. I'm reading it by my own (I have some reasons not to use app.config or any other standart file)
I'm using it for my framework, so user who will change this config file, will use Visual Studio for editing. I want to add Intellisense, to support this config file.
I have found many solutions, but all of them are designed so my .xsd for this config file should be copied to Schema folder in VS. But I need to store it in the same folder as my .xml file. Actually I can't copy or change anything in VS folder - it should be standalone.
How can I do that?
I found an answer to my question by myself.
I need to set targetNamespace to the root of my xml, and place xsd beside with the same targetNamespace.
Don't know why it was so hard to find this information, the answer is very simple

Embed the content from an external file when compiling

Is there a way in Visual Studio (any version) to embed the content of a file in another file upon compiling? For instance, if one wanted to embed an xml file in a vb code file how would it best be done?
Add the file to your project, right click on the file and select its properties. Under "Build Action" change it to "Embedded Resource". Now when you compile the file is automatically embedded as a resource.
Here is an example showing how to access an embedded bitmap resource.
Have a look at Resources. You can create a string resource that has your xml. This is then compiled into your application image.
Brian beat me about the embeded resource as I was looking for the resource URL :)
If you don't mind it actually being in your code, you can use an XML Literal.
I was about to mention using the #include preprocessor directive (for C and C++), but then you mentioned VB. I don't think VB supports such a thing.
I have no idea on how to go about doing this. But the first thought that came to my mind was that of Build Providers (the thing that generate classes from xml file in case of an ORM).
I searched & found 1 more thing called Custom Tools, which can act on a file existing in your solution and can be used to generate code file.
See if this link helps at all - http://www.drewnoakes.com/snippets/WritingACustomCodeGeneratorToolForVisualStudio/
What I've done in the past is write a simple .bat file that concatenates 3 different sources into a final source file that actually gets compiled. The .bat file is run as part of the Pre-Build event.
Project
SourceTop.vb
Source.xml
SourceBottom.vb
All of these files have a Build Action of "None"
Merged.vb
merge.bat
type SourceTop.vb > Merged.vb
type Source.xml >> Merged.vb
type SourceBottom.vb >> Merged.vb

Resources