Reference multitarget class library in VS2017 solution












1















In VisualStudio 2017 I created a class library which targets .net 4.0 (to support legacy applications on win XP) and 4.6.1 framework. I did this by making use of the new .csproj format which allows to specify multiple target frameworks as shown below.



<PropertyGroup>
<TargetFrameworks>net40;net472</TargetFrameworks>
</PropertyGroup>


Building the library for both frameworks works perfectly. I get my two folders, net40 and net472 which contain both a dll for the specific target framework.



In my solution, I now have two further projects. One WinForms App that references my library and a WPF App which also references it. WinForms App should use net40 and WPF App net472 version of my library.



When I add a project reference to the library in my WinForms App it uses net40 version. Everything fine.



But when I reference the class library project to my WPF application (which builds for net472) it also uses the net40 dll. But I want my WPF app to use the net472 version of the library.



Is there any possibility to select the target framework when referencing a multitarget class library as project reference in VS2017?



Update:
When I build a multitarget nuget package from the library and use the package to reference it, everything is fine. WPF app uses net472 and WinForms net40 automatically.










share|improve this question





























    1















    In VisualStudio 2017 I created a class library which targets .net 4.0 (to support legacy applications on win XP) and 4.6.1 framework. I did this by making use of the new .csproj format which allows to specify multiple target frameworks as shown below.



    <PropertyGroup>
    <TargetFrameworks>net40;net472</TargetFrameworks>
    </PropertyGroup>


    Building the library for both frameworks works perfectly. I get my two folders, net40 and net472 which contain both a dll for the specific target framework.



    In my solution, I now have two further projects. One WinForms App that references my library and a WPF App which also references it. WinForms App should use net40 and WPF App net472 version of my library.



    When I add a project reference to the library in my WinForms App it uses net40 version. Everything fine.



    But when I reference the class library project to my WPF application (which builds for net472) it also uses the net40 dll. But I want my WPF app to use the net472 version of the library.



    Is there any possibility to select the target framework when referencing a multitarget class library as project reference in VS2017?



    Update:
    When I build a multitarget nuget package from the library and use the package to reference it, everything is fine. WPF app uses net472 and WinForms net40 automatically.










    share|improve this question



























      1












      1








      1


      1






      In VisualStudio 2017 I created a class library which targets .net 4.0 (to support legacy applications on win XP) and 4.6.1 framework. I did this by making use of the new .csproj format which allows to specify multiple target frameworks as shown below.



      <PropertyGroup>
      <TargetFrameworks>net40;net472</TargetFrameworks>
      </PropertyGroup>


      Building the library for both frameworks works perfectly. I get my two folders, net40 and net472 which contain both a dll for the specific target framework.



      In my solution, I now have two further projects. One WinForms App that references my library and a WPF App which also references it. WinForms App should use net40 and WPF App net472 version of my library.



      When I add a project reference to the library in my WinForms App it uses net40 version. Everything fine.



      But when I reference the class library project to my WPF application (which builds for net472) it also uses the net40 dll. But I want my WPF app to use the net472 version of the library.



      Is there any possibility to select the target framework when referencing a multitarget class library as project reference in VS2017?



      Update:
      When I build a multitarget nuget package from the library and use the package to reference it, everything is fine. WPF app uses net472 and WinForms net40 automatically.










      share|improve this question
















      In VisualStudio 2017 I created a class library which targets .net 4.0 (to support legacy applications on win XP) and 4.6.1 framework. I did this by making use of the new .csproj format which allows to specify multiple target frameworks as shown below.



      <PropertyGroup>
      <TargetFrameworks>net40;net472</TargetFrameworks>
      </PropertyGroup>


      Building the library for both frameworks works perfectly. I get my two folders, net40 and net472 which contain both a dll for the specific target framework.



      In my solution, I now have two further projects. One WinForms App that references my library and a WPF App which also references it. WinForms App should use net40 and WPF App net472 version of my library.



      When I add a project reference to the library in my WinForms App it uses net40 version. Everything fine.



      But when I reference the class library project to my WPF application (which builds for net472) it also uses the net40 dll. But I want my WPF app to use the net472 version of the library.



      Is there any possibility to select the target framework when referencing a multitarget class library as project reference in VS2017?



      Update:
      When I build a multitarget nuget package from the library and use the package to reference it, everything is fine. WPF app uses net472 and WinForms net40 automatically.







      c# visual-studio-2017 class-library multitargeting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 15:09







      Quergo

















      asked Nov 21 '18 at 21:46









      QuergoQuergo

      430414




      430414
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420916%2freference-multitarget-class-library-in-vs2017-solution%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420916%2freference-multitarget-class-library-in-vs2017-solution%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?