Comments (2)
This need is based on sharing .proto
files via NuGet packages accordingly to the described approach in SO: Sharing one gRPC proto file for all solutions
from paket.
To workaround this missing capability, these (similar) approaches are helpful.
Using a package .targets
file
Using a <package ID>.targets
as part of the package, located in a build
folder on the package root level.
This file should have content like this:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target
Name="CopyProtobufs"
BeforeTargets="BeforeBuild">
<CreateItem
Include="$(MSBuildThisFileDirectory)..\content\Protos\**\*.*">
<Output TaskParameter="Include" ItemName="ProtoFiles" />
</CreateItem>
<Copy
SourceFiles="@(ProtoFiles)"
DestinationFolder="$(ProjectDir)\include\%(RecursiveDir)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="true"
/>
<WriteLinesToFile
File="$(ProjectDir)\include\.gitignore"
Lines=".gitignore;foundation/"
Overwrite="true"
Encoding="UTF-8"
/>
</Target>
</Project>
Such a package-related .targets
file is automatically weaved into the build process of a package consumer.
This approach copies the (common) .proto
files to the project folder of the consuming project. In case this project is Git versioned, it makes sense to suppress the tracking of such imported files. That's the aim of the 2nd step - create dynamically a .gitignore
file in the root folder of the imported stuff which ignores the .gitignore
file itself and the folder with .proto
files.
So the consuming project can import the (common) .proto
files that way:
<ItemGroup>
<Protobuf Include="Protos/**/*.proto" ProtoRoot="Protos" AdditionalImportDirs="include/" />
</ItemGroup>
Using a package .props
file
Using a <package ID>.props
as part of the package, located in a build
folder on the package root level.
This file should have content like this:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PkgMessages_Protobuf>$(MSBuildThisFileDirectory)/../content/Protos/</PkgMessages_Protobuf>
</PropertyGroup>
</Project>
Again, such a package-related .props
file is automatically weaved into the build process of a package consumer.
It creates an MSBuild property named PkgMessages_Protobuf
which points to the folder of the .props
files. Later this property can get evaluated in the build process of the package consumer.
So the consuming project can import the (common) .proto
files that way:
<ItemGroup>
<Protobuf Include="Protos/**/*.proto" ProtoRoot="Protos" AdditionalImportDirs="$(PkgMessages_Protobuf)" />
</ItemGroup>
Remarks
In both cases, these files must be part of the package. We keep them next to the .csproj
file and the packaging is ensured via:
<PropertyGroup Label="Protobuf asset root folders">
<Assets_ProtoInclude>Protos/foundation/</Assets_ProtoInclude>
</PropertyGroup>
<ItemGroup Label="NuGet package Protobuf assets">
<_ProtoAssetName Include="messages" />
<_Asset PackagePath="content/Protos/foundation/" Include="@(_ProtoAssetName->'$(Assets_ProtoInclude)%(Identity).proto')" />
<None Include="@(_Asset)" Pack="true" Visible="false" />
</ItemGroup>
<ItemGroup Label="Targets package assets">
<None Include="XYZ.Messages.Protobuf.props" PackagePath="build/XYZ.Messages.Protobuf.props" Pack="true" Visible="false" />
</ItemGroup>
To add additional folders (e.g. with .proto
files), add them comma-separated in the variable _ProtoAssetName
(e.g. Include="messages, events, commands, queries"
.
from paket.
Related Issues (20)
- Paket Restore Targets doesn't work with .NET 6+ HOT 3
- .Net-Framework 4.8.1 not selectable
- Paket does not respect compatible versions of .Net Standard when adding references
- References to delisted versions of Nuget.Packaging
- Paket failing when trying to install dependencies `OpenSslCryptographicException` HOT 2
- Allow updating a transitive dependency HOT 1
- feat!(Paket.restore.targets): Support `dotnet restore` without `paket restore`; avoid null git diffs
- Empty response is not trusted?
- Paket Simplify Removing FSharp.Core from paket.references
- improve use case of `restore` that would not restore anything due to framework restriction and project being with wrong/lower framework version HOT 3
- plans for .NET 9 HOT 1
- Could not detect any platforms warning HOT 2
- concurrent package restores sometimes fail
- Visual studio not restoring packages for projects that target net8.0-windows
- find-packages command fails when using UNC paths
- Install.sh fails on macos with 'could not find a paket source on nuget.org'
- Paket pack fails when building/creating packages for Windows on Linux (docker), even using --build-platform flag HOT 2
- Paket restore IOException: read-only filesystem HOT 2
- Feature Request: an option to `paket install` that would ignore upper bound restrictions
- Changing source url caches old location
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paket.