Context
My project is structures as:
ProjectA (folder)
/- files
/- ProjectA.csproj (targets net48)
/- ProjectA.NetCore.csproj (targets net8.0-windows)
Projects share same files.
Issue
When building my solution – building all my projects – I end up with an error such as:
C:Program Filesdotnetsdk8.0.201SdksMicrosoft.NET.SdktargetsMicrosoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: Assets file 'F:pathProjectA.NetCoreobjproject.assets.json' doesn't have a target for 'net8.0-windows'. Ensure that restore has run and that you have included 'net8.0-windows' in the TargetFrameworks for your project.
I am able to use dotnet restore
for one project (that generates related obj artifacts and build it), then delete obj and do dotnet restore
for other project, and I will end up with needed contents in bin.
Restoring recreates my project.assets.json
for project, and I have everyting set up for good build.
However, I don’t want to do that by hand, since building this solution on my Jenkins pipeline won’t do well.
How could I bypass this?
Post to see if I can match someone with similar experinces.
Note
Since my program is app add-in, due to other constraints – I am stuck with having 2 separate .csprojs. Having single project with 2 target frameworks doesn’t seem like viable option for my use case at the moment.
What I tried so far
I thought genius idea would be to define pre-build events for both projects:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<RemoveDir Directories="$(IntermediateOutputPath)" />
<Exec Command="dotnet restore .ProjectA.csproj" />
</Target>
- delete obj contents
- dotnet restore project
- do “clean” build
But that didn’t work.