我有一个 Windows Azure 云服务项目的解决方案,可以从 VS 和命令行很好地编译。
如果我尝试制作一个包,它在 VS 中可以正常工作,但在命令行中会失败。
这是我在 Powershell 中的命令行:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe .\project.sln --%
/p:Configuration="QA" /p:TargetProfile="CloudQA" /p:Platform="Any CPU" /target:Publish
/nr:false
我有这个错误:
"C:\CI\project\project.sln" (Publish target) (1) ->
"C:\CI\project\WindowsAzure\WindowsAzure.ccproj.metaproj" (Publish target) (11) ->
"C:\CI\project\WindowsAzure\WindowsAzure.ccproj" (Publish target) (12) ->
(PrepareRoleItems target) ->
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Windows Azure Tools\2.0\Microsoft.WindowsAzure.targets(13
02,5): error MSB4096: The item "C:\CI\project\project.WebAPI\project.WebAPI.csproj" in item list "Projec
tReferenceWithConfiguration" does not define a value for metadata "Name". In order to use this metadata, either qualif
y it by specifying %(ProjectReferenceWithConfiguration.Name), or ensure that all items in this list define a value for
this metadata. [C:\CI\project\WindowsAzure\WindowsAzure.ccproj]
编辑 一些有趣的事情:这是我的 csdef 文件
<WorkerRole name="ProjectWorker" vmsize="ExtraSmall">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InternalEndpoint name="InternalEndpoint1" protocol="http" />
</Endpoints>
<ConfigurationSettings>
</ConfigurationSettings>
</WorkerRole>
<WebRole name="Project.Web" vmsize="ExtraSmall">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="http" endpointName="http" />
</Bindings>
</Site>
<Site name="Api" physicalDirectory="..\..\..\Project.WebAPI">
<Bindings>
<Binding name="http" endpointName="http81" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="http" protocol="http" port="80" />
<InputEndpoint name="http81" protocol="http" port="81" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
</WebRole>
如您所见,我在一个 WebRole 上有两个网站。
现在,让我们看一下 ccproj 文件:
<ItemGroup>
<ProjectReference Include="..\Project.Web\Project.Web.csproj">
<Name>Project.Web</Name>
<Project>{5d000123-0000-4b6e-b5fa-72525afca7f5}</Project>
<Private>True</Private>
<RoleType>Web</RoleType>
<RoleName>Project.Web</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
<ProjectReference Include="..\ProjectWorker\ProjectWorker.csproj">
<Name>ProjectWorker</Name>
<Project>{22e99999-1000-4559-8507-a948b7e3d1b0}</Project>
<Private>True</Private>
<RoleType>Worker</RoleType>
<RoleName>ProjectWorker</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
</ItemGroup>
ccproj 中只引用了两个项目,而不是 3 个。
云项目在 sln 中有 3 个依赖项。
如果我在 ccproj 中有这样的参考:
<ProjectReference Include="..\Project.WebAPI\Project.WebAPI.csproj">
<Name>Project.Web</Name>
<Project>{A0F88888-3333-4823-A34F-5F01F0A3FFFF}</Project>
<Private>True</Private>
<RoleType>Web</RoleType>
<RoleName>Project.WebAPI</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
我有这个错误:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Windows Azure Tools\2.0
\Microsoft.WindowsAzure.targets(987,5): error : CloudServices25 : Multiple directories are
specified for role Project.Web. [C:\CI\project\WindowsAzure\WindowsAzure.ccproj]
现在,如果我像这样更新参考:
<ProjectReference Include="..\Project.WebAPI\Project.WebAPI.csproj">
<Name>Project.WebAPI</Name>
<Project>{A0F88888-3333-4823-A34F-5F01F0A3FFFF}</Project>
<Private>True</Private>
<RoleType>Web</RoleType>
<RoleName>Project.Web</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
我有这个错误:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Windows Azure Tools\2.0
\Microsoft.WindowsAzure.targets(987,5): error : CloudServices26 : Cannot find role
named 'Project.WebAPI' in service description file
C:\CI\project\WindowsAzure\bin\UAT\ServiceDefinition.csdef.
[C:\CI\project\WindowsAzure\WindowsAzure.ccproj]