Reputation: 833
I am building a project which produces a nuget package. Configuration for the nuget package is in my csproj file. E.g. I have
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
I also have assets which I want to include in the nuget package To include them I have this in my csproj file
<ItemGroup>
<_PackageFiles Include="$(OutputPath)\clidriver\**">
<BuildAction>None</BuildAction>
<PackagePath>\build\clidriver\</PackagePath>
</_PackageFiles>
</ItemGroup>
When I build from visual studio, assets are nicely included in the nuget package produced. However when I use dotnet.exe to build, assets are not included.
Why this difference?
And is there a trick to make dotnet.exe also include my assets?
Upvotes: 2
Views: 5442
Reputation: 28196
Why this difference?
Building in VS calls msbuild to build the project, and dotnet build also call msbuild to build the project that targets .net core. So if you set the same siwtches, in most situations their build and package results should be the same.
1.It works well in my machine, building in VS2017 and dotnet build with .net core3.0
have same results, they all include the assets. So this issue may be related to your .net core sdk version.I suggest you to install .net core SDK 2.2
or higher to check if it helps. (2.2.109 for VS2017, 2.2.402 for VS2019)
2.And another cause of this issue could be the assets you mentioned above are not found. According to $(OutputPath)\clidriver\**
, you have a clidriver
folder with some assets under output path.
The value of $(OutputPath) can change when you set different configuration. When you build the project(xx.csproj) in debug mode, you should make sure the assets exist in ProjectFolder\bin\Debug\netcoreapp\clidriver
while in release mode, you should make sure the assets exist in ProjectFolder\bin\release\netcoreapp\clidriver
.
So I guess maybe when building in VS, you're in debug mode, and you put the assets there(bin\Debug\netcoreapp\clidriver
), so it contains assets in the nuget package. And when using dotnet build with configuration release, it doesn't contain the assets since the assets are not found in bin\release\netcoreapp\clidriver
. Please check if you're in similar issue.
Upvotes: 1