c# - Azure Project 构建包从 VS 运行,从命令行失败并出现错误 MSB4096

标签 c# azure visual-studio-2012 msbuild

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

最佳答案

我找到了这个链接:Visual Studio 2010 Beta 2 myTODO Error message这个对我有用。该链接中的有值(value)的信息:

It seems like maybe Azure does not like it if you specify anything besides an Azure Role project as a dependency on the service project. I made it so MyWebRole.csproj was dependent on xxx.csproj, instead of MyService.ccproj being dependent on xxx.csproj, and it worked.

关于c# - Azure Project 构建包从 VS 运行,从命令行失败并出现错误 MSB4096,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17048171/

相关文章:

具有动态 SQL 筛选器查询的 Azure 服务总线主题订阅

javascript - 如何重置 <输入类型 = "file">

c# - .net sql 异常处理 - 如何获取 sp 参数/值

c# - 使用 C# 在 uTorrent 中打开 torrent 文件

Azure Kubernetes - 副本与 HPA?

.net - 复制到其他计算机时无法在 WcfTestClient 中添加服务

asp.net-mvc - 当我尝试本地调试 Azure 应用程序时,为什么会收到此错误?

c# - 防止为 EF6 中的特定实体生成表

C# 替换字符串中的特殊字符

azure - 在操作层面停止全局层面的政策执行