【问题标题】:How do I include DLLs in my .csproj file?如何在我的 .csproj 文件中包含 DLL?
【发布时间】:2011-12-11 00:00:21
【问题描述】:

嗯,问题是我没有安装 Visual Studio,我也不想安装它,所以,我制作了一个批处理文件来编译我的 .csproj 文件和我的所有源文件。

问题是我不知道如何包含 .dll 文件。这是我的 .csproj 文件的当前代码:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AssemblyName>Project</AssemblyName>
    <OutputPath>Bin\</OutputPath>
  </PropertyGroup>

  <ItemGroup>
        <!-- .cs files -->
    <Compile Include="program.cs" />
  </ItemGroup>

  <Target Name="Build">
    <MakeDir Directories="$(OutputPath)"      Condition="!Exists('$(OutputPath)')" />
    <Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
  </Target>
</Project>

要在编译过程中包含/引用 dll 文件需要进行哪些更改?

【问题讨论】:

    标签: c# c#-4.0 msbuild compilation csproj


    【解决方案1】:

    您将需要一个 ItemGroup,其中包含名为 Reference 的项目,如下所示:

    <ItemGroup>
        <Reference Include="Microsoft.Practices.Unity" />
        <Reference Include="MvcMiniProfiler">
          <HintPath>..\packages\MiniProfiler.1.6\lib\MvcMiniProfiler.dll</HintPath>
        </Reference>
        <Reference Include="System" />
        <Reference Include="System.configuration" />
        <Reference Include="System.Core" />
        <Reference Include="System.Data.Entity" />
        <Reference Include="System.Runtime.Serialization" />
        <Reference Include="System.Security" />
        <Reference Include="System.Web" />
        <Reference Include="System.Xml.Linq" />
        <Reference Include="System.Data.DataSetExtensions" />
        <Reference Include="Microsoft.CSharp" />
        <Reference Include="System.Data" />
        <Reference Include="System.Xml" />
      </ItemGroup>
    

    如果您引用非 GAC 的 dll,则需要放入 HintPath(请参阅 mvc mini profiler,这应该与您的构建文件位置相关),或者您需要将路径传递给 MSBuild在其 ReferencePath 属性中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多