Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change .NET Target Framework Version in VS 2015 C++ project

As the title says, I want to change the .NET Target Framework Version for my C++ project. I'm trying to compile with the /clr command which I think should enable it?

Here's a screenshot: enter image description here

I'm trying to build a DLL for use in Unity and I want to be able to select the proper framework.

I've tried changing the information in the .vxproj file but I can't find the right tag and when I add it myself it throws errors.

EDIT:

this is the code that contains the methods that can be called in C# to use the C++ code I've written before. I only edited the .h file of the CLR Class library (so the .cpp file is only including the header which should be fine I think)

#pragma once
#include "PortAudioManager.h"

using namespace System;

namespace PortAudioWrapper {

public ref class PortAudioManaged
{
private:
    PortAudioManager* audioManager;
public:
    PortAudioManaged() : audioManager(new PortAudioManager()) {
    }

    virtual ~PortAudioManaged() {
        this->!PortAudioManaged();
    }

    // = Object.Finalize
    !PortAudioManaged() {
        delete audioManager;
        audioManager = nullptr;
    }

    void openStreamManaged() {
        audioManager->openStream();
    }

    void stopStreamManaged() {
        audioManager->stopStream();
    }
};
}
like image 495
Dries Avatar asked Oct 25 '15 11:10

Dries


2 Answers

You should be able to follow the guide at https://msdn.microsoft.com/en-us/library/ff770576.aspx

The .NET framework you can target in C++ is dependent on the toolset you choose. You may find it easier to just download an older version of VS that supports the framework you're looking to work with.

In project file I just created the section looks like the below:

<PropertyGroup Label="Globals">
   <ProjectGuid>{48ACEC98-3369-486F-9033-8C433D408570}</ProjectGuid>
   <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
   <Keyword>ManagedCProj</Keyword>
   <RootNamespace>ClassLibrary1</RootNamespace>
   <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
like image 97
Mark E Avatar answered Sep 22 '22 02:09

Mark E


Using VS2015, I had to upgrade the .Net target of a managed C++ DLL from 3.5 to 4.5.1. In the Configuration Properties-General settings, the ".Net Target Framework Version" is greyed out and its value box is not editable.

  1. Open the Name.vcxproj file in notepad.
  2. Navigate to: "<"PropertyGroup Label="Globals" ""
  3. Add: "<"TargetFrameworkVersion""v4.5.1"<"/TargetFrameworkVersion"
  4. Save the updated project file, and reload into VSS2015.

NOTE: Remove the "" around the angle brackets. Then when the project is reloaded into VS2015, you can see the .Net version listed in settings. In my case it was V4.5.1.

like image 41
Ron Green Avatar answered Sep 20 '22 02:09

Ron Green