将AzureServiceProject Node.js发布到Windows Server 2012

我试图使用Powershell“Publish-AzureServiceProject”cmdlet发布一个Node.js包到Azure。

使用默认的osFamily =“2”(Windows Server 2008 R2)它按预期工作,但是当我使用osFamily =“3”(Windows Server 2012)发布时,出现以下错误:

上载软件包所需的名为NetFx35的function在为部署select的OS *中不可用。

很明显,我没有使用.Net,但3.5是默认的,防止我上传的包。

指定.Net 4.5我读了我需要创build一个roleproperties.txt文件,其中包含:

TargetFrameWorkVersion = V4.5

并通过/ rolePropertiesFile传递给cspack。

但是,因为我没有自己调用cspack,我怎么能通过Publish-AzureServiceProject传递给cspack? 还是有另一种解决方法?


目前我的ServiceDefinition看起来像这样:

<?xml version="1.0"?> <ServiceDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Foo" upgradeDomainCount="1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> <WorkerRole name="Bar"> <Imports> <Import moduleName="RemoteForwarder" /> <Import moduleName="RemoteAccess" /> </Imports> <Startup> <Task commandLine="setup_worker.cmd &gt; log.txt" executionContext="elevated"> <Environment> <Variable name="EMULATED"> <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" /> </Variable> <Variable name="RUNTIMEID" value="node" /> <Variable name="RUNTIMEURL" value="http://nodertncu.blob.core.windows.net/node/0.6.20.exe" /> </Environment> </Task> </Startup> <Endpoints> <InputEndpoint name="HttpIn" protocol="tcp" port="80" /> </Endpoints> <Runtime> <Environment> <Variable name="PORT"> <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpIn']/@port" /> </Variable> <Variable name="EMULATED"> <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" /> </Variable> </Environment> <EntryPoint> <ProgramEntryPoint commandLine="runnode.cmd" setReadyOnProcessStart="true" /> </EntryPoint> </Runtime> </WorkerRole> </ServiceDefinition> 

因此,目前,您需要做一些工作才能使OSFamily = 3与非.Netangular色一起工作。 从本质上说,你需要自己运行cspack来创build一个包,并指定一个允许你定位.Net 4.5的angular色属性文件(是的,即使你没有使用.Net,你也需要说服cspack工具,重新使用.Net 4.5)。

这里是步骤:

  1. 使用Webangular色创build一个新的节点项目。
  2. 修改cscfg以设置OS Family = 3。
  3. 将下面的roleproperties.txt放到服务的根目录下。
  4. 启动“Windows Azure命令提示符”,然后转到服务根文件夹。
  5. 运行这个命令:cspack ServiceDefinition.csdef / role:WebRole1; WebRole1 / sites:WebRole1; Web; WebRole1 /rolePropertiesFile:WebRole1;RoleProperties.txt /out:package.cspkg
  6. login到门户并创build服务/手动上传cspkg

roleproperties.txt的内容:

TargetFrameworkVersion=v4.5

由于Node SDK在不使用cspack.exe的情况下构build包(以保持平台独立架构),因此不能使用“/ rolePropertiesFile”选项。

作为解决方法,您可以在ServiceDefinition中使用Runtime – > EntryPoint – > NetFxEntryPoint – > targetFrameworkVersion =“v4.5”来设置targetFrameworkVersion设置,如下所示:

 <?xml version="1.0"?> <ServiceDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NodeAvkash" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> <WebRole name="WebRole1" vmsize="ExtraSmall"> <Imports /> <Startup> <Task commandLine="setup_web.cmd &gt; log.txt" executionContext="elevated"> <Environment> <Variable name="EMULATED"> <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" /> </Variable> <Variable name="RUNTIMEID" value="node;iisnode" /> <Variable name="RUNTIMEURL" value="http://nodertncu.blob.core.windows.net/node/0.6.20.exe;http://nodertncu.blob.core.windows.net/iisnode/0.1.21.exe" /> </Environment> </Task> </Startup> <Endpoints> <InputEndpoint name="Endpoint1" protocol="http" port="80" /> </Endpoints> <Sites> <Site name="Web"> <Bindings> <Binding name="Endpoint1" endpointName="Endpoint1" /> </Bindings> </Site> </Sites> <Runtime executionContext="elevated"> <EntryPoint> <NetFxEntryPoint assemblyName="WebRole1.dll" targetFrameworkVersion="v4.5" /> </EntryPoint> </Runtime> </WebRole> </ServiceDefinition>