0

Backstory:

I can get an output from a json I need to set the json manually to "Copy always" under "Copy to Output Directory"; is there any way I can automatically do this?

Because I spent like 15 minutes trying to figure out why I'm not getting any output, so doing this step automatically would cause less head-aches :D

enter image description here

Some of my code where I would like to implement it

static Config()
{
    if (!Directory.Exists(configFolder))
    {
        Directory.CreateDirectory(configFolder);
    }

    if(!File.Exists(path))
    {
        bot = new BotConfig();
        string json = JsonConvert.SerializeObject(bot, Formatting.Indented);
        File.WriteAllText(path, json);
    }
    else
    {
        string json = File.ReadAllText(path);
        bot = JsonConvert.DeserializeObject<BotConfig>(json);

        if (bot.token == null)
        {
            Console.WriteLine("Could not optain bot.token from {0}", path);
        }
    }
}

I hope this make sense, I couldn't find anything related to this.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
MewTwo
  • 465
  • 4
  • 14
  • How many files are you using that you need this? – ProgrammingLlama Dec 11 '18 at 05:24
  • I found [this](https://stackoverflow.com/questions/14675924/is-it-possible-to-automatically-set-copy-to-output-directory-when-creating-fil) but I have no idea if it's still relevant in VS2017. – ProgrammingLlama Dec 11 '18 at 05:29
  • Well not many yet, but i would find it very usefull. – MewTwo Dec 11 '18 at 05:30
  • As a hacky workaround, it wouldn't take a lot of effort to write a console exe that you launch using the pre build, it scans the project file and modifies entries the fails with some non zero exist code halting the build, vs offers to reload the project, next build it works out because there are no changes to make (tool exits normally) – Caius Jard Dec 11 '18 at 05:58
  • It use a database/unified file to hold your scripts so there's only one of them – Caius Jard Dec 11 '18 at 06:01
  • @MewTwo How your files created? Automatically or by "Add/New Item..."? – Belurd Dec 11 '18 at 08:46
  • @Belurd Automatically yes, that is how i get them. – MewTwo Dec 11 '18 at 13:54
  • @MewTwo I just thought that you can create your own template with predefined value for "Copy to Output Directory", but it seems that it will not work for you. – Belurd Dec 11 '18 at 13:59

0 Answers0