Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm working on a project structure with multiple projects serving the same set of static files.

At start each project will server both the static files and the API services but later on I plan to separate some of them into multiple projects.

  • ProjectA will server both static files and API
  • ProjectB1 will only serve the same static files as in ProjectA
  • ProjectB2 will only serve the API

In a classic VS library you can have files marked as content. These will be included in the build output of any project that references that library.

I tried to make a project ProjectStatic containing the static files and reference it from both ProjectA and ProjectB1 but none of the files in ProjectStatic are included in the output of ProjectA nor ProjectB1.

Can this be done using project.json?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Have a look at how PinpointTownes implemented this in his OpenIddict project.

You can use the UseStaticFiles call with a EmbeddedFileProvider. It's part of the rc1-final package, as you can see here. The relevant code is found on GitHub.

Just for future readers:

app.UseStaticFiles(new StaticFileOptions {
        FileProvider = new EmbeddedFileProvider(
            assembly: Assembly.Load(new AssemblyName("OpenIddict.Assets")),
            baseNamespace: "OpenIddict.Assets")
});

OpenIddict.Assets is the assembly/project name that contains the static resources.

Update:

After digging a bit through the source and finding the right repository, there is also a PhysicalFileProvider you may be able to use instead of packing it into the assembly and point to an arbitrary folder on the file system.

app.UseStaticFiles(new StaticFileOptions {
        FileProvider = new PhysicalFileProvider("/path/to/shared/staticfiles")
});

Update 2:

Just for the sake of completeness, there is also a CompositeFileProvider which you could use to have multiple IFileProviders to create some kind of virtual file system structure, i.e. if the file is not found in the PhysicalFileProvider given location, load it from an EmbeddedFileProvider.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...