dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.6k stars 1.04k forks source link

ClickOnce Publish Failure - library not found #15667

Open shanieMoonlight opened 3 years ago

shanieMoonlight commented 3 years ago

I'm having a problem publishing a WPF app.

It seems to be caused by the "Publisher" looking for the dll's (from referenced projects) in the wrong place.

I'm getting this error in the Output Window:

Metadata file 'C:*\DeviceInfo\bin\Release\net5.0-windows\DeviceInfo.dll' could not be found Metadata file 'C:*\Helpers\bin\Release\net5.0-windows\Helpers.dll' could not be found

The referenced projects in question are not necessarily window projects so they are getting published to their own bin\Release\net5.0 folders.

The net5.0-windows folder is not getting generated but the Publisher is still looking for them there.

The app runs fine from Visual Studio in Debug and Release mode.

Do I have to create these folders myself and the copy and paste into them or is there a smarter way? Is this a bug?

carlossanlop commented 3 years ago

Since this is a Publish related issue, seems to belong to dotnet/sdk. Moving there.

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

shanieMoonlight commented 3 years ago

For anyone interested here's how I solved it. I changed the target framework from "net5.0" to "net5.0;net5.0-windows" in all the referenced projects.

I'm not sure if this was the best way to handle it but it seems to have worked.

I feel like it should be done automatically by the publishing program.

sfoslund commented 3 years ago

I'm not quite following what your scenario is from the original description, do you have a WPF project referencing net5.0 windows projects? Can you provide a minimal repro solution? Thanks!

shanieMoonlight commented 3 years ago

Hi @sfoslund here's a repo: https://github.com/shanieMoonlight/ClickOnceTest

If you look at the ClickOnceHelper.csproj the target framework is set to <TargetFramework>net5.0</TargetFramework>

This will run fine from VS but if I try to publish it with ClickOnce I get the following error: Assets file 'C:\Users\Shane\Documents\Visual Studio 2019\Projects\ClickOnceTest\ClickOnceTest\ClickOnceHelper\obj\project.assets.json' doesn't have a target for 'net5.0-windows'. Ensure that restore has run and that you have included 'net5.0-windows' in the TargetFrameworks for your project.

If I change the target framework to <TargetFrameworks>net5.0;net5.0-windows</TargetFrameworks> it will publish.

It just seems weird that it VS can figure out how to run it but can't figure out how to publish it unless I add "net5.0-windows" to the TargetFrameworks.

sfoslund commented 3 years ago

@shanieMoonlight can you provide the version of VS and the SDK you're using? Did you try restoring then rerunning publish as the error message indicates?

shanieMoonlight commented 3 years ago

@sfoslund I've tried restoring and republishing a load of times. The only thing that did it was to declare that the library was targeting net5.0-windows. Basically the publisher is expecting to see the referenced project .dlls in a folder named net5.0-windows, and my VS won't do it unless I explicitly state it in the csproj. I think this is because the WPF project (the main project) is targeting net5.0-windows.

My VS is 2019 Version 16.8.4.

Did you try publishing the repo that I gave you? Did it work for you?

sfoslund commented 3 years ago

@dsplaisted is this a known issue with 16.8?

dsplaisted commented 3 years ago

@shanieMoonlight I don't see a repo at https://github.com/shanieMoonlight/ClickOnceTest. Did you push it to GitHub?

@wli3 Can you tag the right ClickOnce folks to look at this?

shanieMoonlight commented 3 years ago

@dsplaisted Sorry the repo was set to private. Try again and let me know if youcan't see it. I'm not an expert at GitHub