简体   繁体   中英

Possible to regenerate designer.cs file without Visual Studio?

I have few frequently changeable fields stored in Resources.resx which auto generates the file Resources.designer.cs. It has email addresses, location paths which are to be updated based on needs

Now I would like to make the application usable even for a non developer - Even a lay man must be able to edit the email address & Paths.

Had a thought that if someone edits the .resx file(which is easily editable even in notepad) can I write some .exe code to auto generate the corresponding designer.cs for it?

Thanks for understanding..

If visual studio can do it, you can do it. But I think letting a non-technical person edit an xml file is asking for trouble. What I would do is build a small editing tool which pulls out only those fields you want to change, displays them in a simple form for altering, then writes them back to to the resx before rebuilding the designer.

I have done something similar to this for editing an application.exe.config file so that configurations can be changed without danger of (even a technical person) killing the thing with a typo, which is all too easy.

You could use something like

    private void ReadResxFile(string filename)
    {
        if (System.IO.File.Exists(filename))
       {
            using (ResXResourceReader reader = new ResXResourceReader(filename))
            {
                //TODO
            }
        }
    }
    public void SaveResxAs(string fileName, string key, string value)
    {
        try
        {
            using (ResXResourceWriter writer = new ResXResourceWriter(fileName))
            {
                writer.AddResource(key, value);
                writer.Generate();
            }
        }
        catch (Exception error)
        {
            throw error;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM