The easiest way is copying the files in the Resources/raw into the ProjectName.Web. And then you can access the file by the following code in the ProjectName.Web:
var a = File.ReadAllText(Directory.GetCurrentDirectory()+"/test.txt"); // the test.txt is under the `ProjectName.Web` project
The ProjectName project and ProjectName.Web project will both contain the ProjectName.Shared prject, but they will not contain each other. So you don't have to worry about the duplicates.
If you still want there is only one copy of these reference files. You can just put them in the ProjectName.Shared/wwwroot folder.
- For the files you used in the razor page.
Such as images displayed in the razor page. You can put them in the ProjectName.Shared/wwwroot/images folder. Such as ProjectName.Shared/wwwroot/images/test.jpg. Then you can use it by:
<img src="_content/MauiApp10.Shared/images/test.jpg" />
- For the files you want to access by IO operation.
Such as txt file. You can put them in the ProjectName.Shared/wwwroot/files folder. Such as ProjectName.Shared/wwwroot/files/test.txt.
- You can access the txt file in the ProjectName project by:
var value = await FileSystem.OpenAppPackageFileAsync("wwwroot/_content/ProjectName.Shared/files/test.txt");using StreamReader sr = new StreamReader(value);var text = sr.ReadToEnd();
- You can access the txt file in the ProjectName.Web project by:
HttpClient client = new HttpClient();client.BaseAddress = new Uri("http://localhost:5079");// the baseaddress is in the ProjectName.Web/launchingSettings.jsonvar response = await client.GetStringAsync(@"/_content/ProjectName.Shared/files/test.txt");