如何在 .csproj 文件中包含 DLL?

发布于 2024-12-10 18:49:49 字数 780 浏览 0 评论 0原文

好吧,问题是我没有安装 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 文件?

Well, the thing is that I don't have Visual Studio installed and I don't want to install it, so, I made a batch file that compiles my .csproj file and all of my source files too.

The problem is that I don't know how to include .dll files. Here is my current code for my .csproj file:

<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>

What do I need to change to include / reference a dll file into the compilation process?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素食主义者 2024-12-17 18:49:49

您将需要一个 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'd dll,则需要放入 HintPath(请参阅 mvc mini profiler,这应该与您的构建文件位置相关),或者您需要将 MSBuild 的路径传递到其 ReferencePath 属性中。

You will need an ItemGroup with items called Reference like so:

<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>

If you are referencing non-GAC'd dlls, you will need to either put in the HintPath (see mvc mini profiler, this should be relative to your build files location), or you will need to pass the path to MSBuild in its ReferencePath property.

要走干脆点 2024-12-17 18:49:49

您可以按如下方式简化 .csproj 中的引用:

<Reference Include="lib\someLib.dll" />

通配符也应该有效:

<Reference Include="lib\*.dll" />

来源: https://github.com/dotnet/sdk/issues/24816#issuecomment-1117948140

You can simplify the reference in the .csproj as follows:

<Reference Include="lib\someLib.dll" />

Wildcards should also work:

<Reference Include="lib\*.dll" />

Source: https://github.com/dotnet/sdk/issues/24816#issuecomment-1117948140

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文