Nuget doesn't work with Cloud Service project in Visual Studio 2013?

Your instructions for installing NuGet in a WebRole says to do this:

Open the Visual Studio solution containing your Cloud Service project. Then, open the NuGet Package Manager and execute the following command:

Install-Package NewRelicWindowsAzure

However, in Visual Studio 2013 Update 2, this doesn’t seem possible. The Package Manager Console does not allow you to choose a Cloud Service project as the Default Project and therefore you can’t seem to install that package into the web role.

Example, if I create a brand new Windows Azure Cloud Service project with a single web role, I get 2 projects in my solution - one for the Cloud Service (the web role in this case) and one for the Web Application itself. when I open the Package Manager Console, the only project available in the Default project dropdown is the Web Application - the Cloud Service project is not available there.

Am I missing something? Is there another way to do the install with Nuget?

You actually do want to install the NuGet package with the role project selected. Some components of the Cloud project will be modified during installation but the components will go in the application itself. If you use multiple roles in the same project (e.g. a Web Role for the app and a Worker Role for background processing), be sure to install a separate copy of the package for each role.

OK, gotcha. So, I got this to work with a very simple project in Visual Studio where I only have one Web Application and one Web Role.

However, my main Visual Studio solution has 20 projects and 3 Cloud Service projects (2 Web Roles and 1 Worker Role). So, when I try to install New Relic into my Web Application, it doesn’t seem to know how to find the correct Cloud Service Web Role project to update. Here are the results:

PM> Install-Package NewRelicWindowsAzure
Installing 'NewRelicWindowsAzure 3.6.177.0'.
Successfully installed 'NewRelicWindowsAzure 3.6.177.0'.
Adding 'NewRelicWindowsAzure 3.6.177.0' to MyWebApplicationProject.
Successfully added 'NewRelicWindowsAzure 3.6.177.0' to MyWebApplicationProject.
***Updating project items newrelic.cmd, NewRelicAgent_x64_3.6.177.0.msi, and NewRelicServerMonitor_x64_3.2.6.0.msi***
***Updating the Windows Azure ServiceDefinition.csdef with the newrelic.cmd Startup task***
Unable to find the ServiceDefinition.csdef file in your solution, please make sure your solution contains an Azure deployment project and try again.
***Updating the Windows Azure ServiceConfiguration.*.cscfg files with the license key***
Unable to find any ServiceConfiguration.cscfg files in your solution, please make sure your solution contains an Azure deployment project and try again.
***Updating the projects .config file with the NewRelic.AppName***
***Package install is complete***

Now that I’ve seen the changes it makes (by looking at the simple project I tested with) I can make those changes manually. Is that the only option? Any idea why the New Relic Nuget package can’t correlate my web project with the corresponding web role cloud service project within my solution?

I can see that the references to roles that compose a Cloud Service project are found in the Roles folder and also explicitly named in ServiceDefinition.csdef and ServiceConfiguration.cscfg. I don’t see how a role project itself knows what Cloud project it belongs to or how the NuGet package knows where to find the find the ServiceDefinition.csdef and ServiceConfiguration.cscfg files in the “parent”. It seems that the installer checks the entire solution.

Do your 3 Cloud Service projects appear in the Roles folder for the overall Cloud project? These are the 3 projects that will support the .NET agent. For comparison, here’s what I see after installing the NuGet package in a Web Role:

Is the excerpt from the package manager that you posted the output you get when trying to install to a Web Role? Are your Web Roles made up of other projects?

Actually, my project looks more like this:

Notice, 2 separate Web Apps and each web app has it’s own Cloud Service (Web Role). (We also have a console app that runs in a worker role which includes it’s own Cloud Service Worker Role project - but I excluded that here for simplicity.)

I was able to reproduce the error by setting it up this way:

  1. Create a Blank Solution.
  2. Add a ASP.NET Web Application (MVC/API/whatever)
  3. Add a Windows Azure Cloud Service (don’t choose anything on the “New Windows Azure Cloud Service” dialog) and then connect that to the Web App from Step 2 (right click on Roles > Add > Web Role Project in Solution).
  4. Add a second ASP.NET Web Application (MVC/API/whatever)
  5. Add a second Windows Azure Cloud Service and then connect that to the Web App in Step 4.
  6. Now try to run “Install-Package NewRelicWindowsAzure” on one of the Web Apps. You should get similar output to what I posted earlier.

Here is the results when I run the NuGet package on WebApp1 in this solution:

PM> Install-Package NewRelicWindowsAzure
Installing 'NewRelicWindowsAzure 3.6.177.0'.
Successfully installed 'NewRelicWindowsAzure 3.6.177.0'.
Adding 'NewRelicWindowsAzure 3.6.177.0' to WebApp1.
Successfully added 'NewRelicWindowsAzure 3.6.177.0' to WebApp1.
***Updating project items newrelic.cmd, NewRelicAgent_x64_3.6.177.0.msi, and NewRelicServerMonitor_x64_3.2.6.0.msi***
***Updating the Windows Azure ServiceDefinition.csdef with the newrelic.cmd Startup task***
Unable to find the ServiceDefinition.csdef file in your solution, please make sure your solution contains an Azure deployment project and try again.
***Updating the Windows Azure ServiceConfiguration.*.cscfg files with the license key***
Unable to find any ServiceConfiguration.cscfg files in your solution, please make sure your solution contains an Azure deployment project and try again.
***Updating the projects .config file with the NewRelic.AppName***
***Package install is complete***

Thanks for the detailed steps you use to reproduce this issue @jglinsek. I’m unable to reproduce the error using that process unfortunately. I’m not sure if it’s relevant, but what is Startup Project set to in properties for the solution? Also, do you have source control rigged up in any way when you run through the steps listed?

So, I missed one step when I wrote out the steps. We have our Azure Cloud Service projects in a “Solution folder” (see my screenshot in my last post, I have a solution folder called “Azure”). So, in my test project, I tried to move them out of the solution folder and redid the NuGet install and that worked.

I tested the same in my real app and it also worked there. So, nesting the Cloud Service projects in the Solution folder is apparently the problem. Workaround seems to be to temporarily move the Cloud Service project out of the Solution folder, do the install and then you can move it back (or not use Solution folders!).

Thanks for your help.

1 Like

Thanks for spotting that @jglinsek. I’ll report this to our developers in case there’s a way they can make the installer handle this solution structure more gracefully. In the meantime, I’m glad you found a workaround.

This is the same issue i reported in this case:

and the cause is this:

the installer powershell script still hasn’t been updated to find cloud projects in solution folders. :frowning:

Thanks for helping us correlate these two incident reports @michael2. I have updated our developers.

@QuietWyatt I am also having this issue. are there any updates on this? when will an updated NuGet package be published?

@rezidual I’m not sure when this will be resolved but we will post here with any updates. For now @jglinsek found the workaround of temporarily moving each Cloud Service project out of the Solution Folder so that it’s a direct child of the main project. You can also manually update ServiceDefinition.csdef and ServiceConfiguration.cscfg

@QuietWyatt Do you have examples of how to update the ServiceDefinition and ServiceConfiguration files manually? Because they aren’t updating using the powershell script (I event moved the cloud services project into the main web role project directory), we will be trying to update those configurations manually.

I was actually able to get this to work, but for those who need to edit the configuration manually, here’s an example of the ServiceDefinition.csdef (which is the one that is tricky).

<WebRole name="Orchard.Web" vmsize="Medium">
  <ConfigurationSettings>
    <Setting name="NewRelic.LicenseKey" />
  </ConfigurationSettings>
  <Startup>
    <Task commandLine="newrelic.cmd" executionContext="elevated" taskType="simple">
      <Environment>
        <Variable name="EMULATED">
          <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
        </Variable>
        <Variable name="IsWorkerRole" value="false" />
        <Variable name="LICENSE_KEY">
          <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='NewRelic.LicenseKey']/@value" />
        </Variable>
      </Environment>
    </Task>
  </Startup>
</WebRole>

The service configuration files are easy. Just one line with the license key:

  <Setting name="NewRelic.LicenseKey" value="xxxxxxxxx" />
2 Likes

This was the key for my issue. Thanks for the snippet. Too bad it’s not readily available on the “How To” section.

@gtandeciarz - Thanks for the snippet and @colemike thanks for the confirmation that the fix works for you as well. We will check into updating the “How To” to include this information until the nuget package is updated appropriately.

1 Like