问题 Azure项目构建包从VS工作,从命令行失败,错误MSB4096


我有一个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]

11749
2018-06-11 15:36


起源



答案:


我找到了这个链接: Visual Studio 2010 Beta 2 myTODO错误消息 这个对我有用。来自该链接的有价值信息:

如果您将Azure角色项目之外的任何内容指定为服务项目的依赖项,那么Azure似乎可能不喜欢它。我做了它,所以MyWebRole.csproj依赖于xxx.csproj,而不是依赖于xxx.csproj的MyService.ccproj,并且它有效。


6
2018-03-12 03:17





这篇文章解决了我的问题: http://michaelcollier.wordpress.com/2013/01/14/multiple-sites-in-a-web-role/

如果您在一个webrole上有多个网站,那么必须阅读!


3
2018-06-12 12:52





在从命令行构建我的云项目时,我偶然发现了类似的问题,特别是如果Web项目引用的话,我会遇到此异常。 VirtualDirectory 标记被标记为云项目的构建依赖项。

为了避免这种情况,请确保Web项目已编译并包含在 cspack,我想出了一个比其中引用的程序更简单的程序 Swell的答案  - 特别是它不需要改变项目文件,只需要按照精确的顺序调用两个目标:

  1. 确保 Configuration Manager Web项目将在所需的解决方案配置中重建(例如,确保它是在其下构建的 Release 组态);
  2. 确保Web项目不是云项目的构建依赖项;
  3. 例如,重建解决方案

    MsBuild solution.sln /t:Rebuild ...
    

    这样就可以重新编译Web项目。

  4. 例如,执行云项目的发布

    MsBuild solution.sln /t:cloudproject.ccproj:publish ...
    

    Web项目将正确复制到 cspack 文件。


1
2017-10-29 18:27