Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

c# - New .csproj format - How to specify entire directory as "linked file" to a subdirectory?

With the new .csproj format (as well as the old), it is possible to add files as linked outside of the project folder:

 <EmbeddedResource Include="......DemoSample.cs" Link="ResourcesSample.cs" />

It is also possible to use a glob pattern to include multiple files:

<EmbeddedResource Include="......Demo*.cs" />

But how do you combine the two?

What I Tried

  1. <EmbeddedResource Include="......Demo*.cs" Link="Resources*.cs" />
  2. <EmbeddedResource Include="......Demo*.cs" Link="Resources*" />
  3. <EmbeddedResource Include="......Demo*.cs" Link="Resources" />

The first two only create a single linked file (with exactly the name *.cs and * respectively). The third simply errors out.

Is there a way to combine globbing with linked files to a specific location in the target project? If not, how can I link all the files in a directory without knowing how many or what their names are?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

While this was previously possible using the %(RecursiveDir) metadata when using glob expansion ( Link="Resources\%(RecursiveDir)%(Filename)%(Extension)"), the 2.0.0 version of the .NET Core SDK allows the use of a new LinkBase metadata:

<EmbeddedResource Include="......Demo***.cs" LinkBase="Resources" />

Note that you need to install the 2.0.0 in addition to the recently released VS 2017 15.3 (and ensure no global.json selects a lower version).

It was introduced with this pull request which is probably the best documentation at the moment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...