0

So I've made a self-contained release of a project with Visual Studio Code. The EXE is working on ubuntu and windows, but can't get it to work on os-x.

I'm using a simple data.json to store some data. The error that occurs on the os-x release, is that it can't find the correct path to data.json. I get this message:

Could not find file '/Users/User/data.json'.

That is not where I store the release or data.json. I store it in the root-directory of the project. Seems like the application is looking for the json-file in my system root directories. How do I fix this?

My XML csproj:

 <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <RuntimeIdentifiers>win10-x64;osx.10.11-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.json" Version="10.0.3" />
  </ItemGroup>
</Project>
Jesper
  • 2,044
  • 3
  • 21
  • 50
  • The csproj is almost never useful. The part of your code that opens the file, on the other hand, almost certainly contains your issue. – zneak Oct 25 '17 at 00:05
  • @zneak I just have a static reference to the source: private static string _source = "data.json"; Which is used to read and write to the file – Jesper Oct 25 '17 at 02:42
  • Wondering if my local file data.json should be declared in a "PackageReference"... – Jesper Oct 25 '17 at 02:44
  • No, PackageReference is for libraries. Just using "data.json" makes the path relative to the application's current working directory. See https://stackoverflow.com/questions/37041658/c-sharp-application-relative-paths – zneak Oct 25 '17 at 02:47
  • Also, from where do you run the generated executable? if you open a new terminal, the working directory is your user directory and if you call `./path/to/app` it will look in that directory for any relative paths since it is the current working directory – Martin Ullrich Oct 25 '17 at 05:48

0 Answers0