(1) Is this doable with PackageReference and contentFiles ?
I am afraid you could not add those files to the Android project, but I would like provide an alternative solution here, add those files to the output folder.
You could use PackageReference and contentFiles directly for the latter two requirements, config.exe and Files. But for the first requirement Directory.Buil.props, we need do more things, since it is copied to the solution folder rather than project folder.
For the latter two requirements, config.exe and Files, we could use .nuspec file with contentFiles to including them, need set copyToOutput="true", like:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MyTestCore</id>
<version>4.0.0</version>
<authors>TestContentFile</authors>
<owners>TestContentFile</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package Description</description>
<contentFiles>
<files include="any/any/config.exe" buildAction="content" flatten="true" copyToOutput="true"/>
<files include="any/any/Files/1.txt" buildAction="content" flatten="true" copyToOutput="true"/>
<files include="any/any/Files/2.txt" buildAction="content" flatten="true" copyToOutput="true"/>
</contentFiles>
</metadata>
<files>
<file src="contentFiles/any/any/config.exe" target="contentFiles/any/any/config.exe" />
<file src="contentFiles/any/any/Files/1.txt" target="contentFiles/any/any/Files" />
<file src="contentFiles/any/any/Files/2.txt" target="contentFiles/any/any/Files" />
</files>
</package>
After packing this .nuspec and install the generated package to the project.
However, we could not find those files under the References node. That because the project still use the old csproj with packagereference not using the new sdk csproj.
Old csproj to new csproj: Visual Studio 2017 upgrade guide
Besides, copying files into the project's source directory is not supported and has been a discouraged practice for classic projects. The contentFiles section controls the msbuild items that are generated for these files into the obj\projectname.csproj.nuget.g.props file. And check the project.assets.json file you can find:
"targets": {
"MonoAndroid,Version=v7.1": {
"MyTestCore/5.0.0": {
"type": "package",
"contentFiles": {
"contentFiles/any/any/Files/1.txt": {
"buildAction": "Content",
"codeLanguage": "any",
"copyToOutput": true,
"outputPath": "1.txt"
},
"contentFiles/any/any/Files/2.txt": {
"buildAction": "Content",
"codeLanguage": "any",
"copyToOutput": true,
"outputPath": "2.txt"
},
"contentFiles/any/any/config.exe": {
"buildAction": "Content",
"codeLanguage": "any",
"copyToOutput": true,
"outputPath": "config.exe"
}
}
See: nuspec contentFiles not added to a project
Then we need build this project, those files will copied to the output folder.
For the first requirement, in order to add the Directory.Buil.props to the solution folder, we need create a custom copy target in the YourPackageName.targets file, then add this .targets file into the \build folder, the .targets file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<MySourceFiles Include="<FilePath>\Directory.Buil.props"/>
</ItemGroup>
<Target Name="CopyFiles" BeforeTargets="Build">
<Copy
SourceFiles="@(MySourceFiles)"
DestinationFolder="<SolutionFolder>"
/>
</Target>
</Project>
The .nuspec file like:
<files>
<file src="<>\xxx.targets" target="build" />
</files>
Hope this helps.