我可以用以下命令构建我的项目......
csc /reference:lib\Newtonsoft.Json.dll SomeSourceFile.cs
Run Code Online (Sandbox Code Playgroud)
...但是当我使用这个命令时......
msbuild MyProject.csproj
Run Code Online (Sandbox Code Playgroud)
...使用以下.csproj文件,我的.dll参考不包括在内.有什么想法吗?
<PropertyGroup>
<AssemblyName>MyAssemblyName</AssemblyName>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="SomeSourceFile.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>lib\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<Target Name="Build">
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
<Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
</Target>
Run Code Online (Sandbox Code Playgroud)
您没有将您的Reference组连接到Csc任务.此外,您指定的方式的引用也无法直接在任务中使用.MSBuild附带的任务包括ResolveAssemblyReference,它能够将短的程序集名称和搜索提示转换为文件路径.你可以看到里面如何使用它c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets.
没有ResolveAssemblyReference,你可以做的最简单的事情是这样写:
<PropertyGroup>
<AssemblyName>MyAssemblyName</AssemblyName>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="SomeSourceFile.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="lib\Newtonsoft.Json.dll" />
</ItemGroup>
<Target Name="Build">
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
<Csc Sources="@(Compile)" References="@(Reference)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
</Target>
Run Code Online (Sandbox Code Playgroud)
请注意,引用项指定引用的程序集的直接路径.
| 归档时间: |
|
| 查看次数: |
5794 次 |
| 最近记录: |