简体   繁体   English

如何在VSCode中使用调试/发布移动引用的DLL?

[英]How do i move referenced DLLs with debug/release in VSCode?

Set up 设定

I converted a C# VS2015 console application project over to VSCode and im trying to add a DLL reference and move any referenced DLLs on build. 我将一个C#VS2015控制台应用程序项目转换为VSCode,并尝试添加DLL引用并在构建时移动任何引用的DLL。

To start off, Dotnet add package didnt work, with the error The project does not support adding package references through the add package command. 首先, Dotnet add package The project does not support adding package references through the add package command.正常工作,错误The project does not support adding package references through the add package command. so i added the project manually to the .csproj file. 所以我手动将项目添加到.csproj文件中。 The package i want to add is a local version, located at ./Lib/AutoItX 我要添加的软件包是本地版本,位于./Lib/AutoItX

Lib/
   └── AutoItX
        ├── AutoItX3_x64.dll
        ├── AutoItX3.Assembly.dll
        ├── AutoItX3.Assembly.xml
        └── AutoItX3.dll

additions to .csprog 添加到.csprog

<ItemGroup>
    <Reference Include="AutoItX">
      <HintPath>.\Lib\AutoItX\AutoItX3.Assembly.dll</HintPath>
    </Reference>
  </ItemGroup>

The reference works, and if i manually move the DLL into the Debug folder, it finds it and all is well. 参考工作,如果我手动将DLL移动到Debug文件夹,它会找到它,一切都很好。

Question

Is there a way to automate moving the DLL into the folder? 有没有办法自动将DLL移动到文件夹中?

currently, after a fresh run, my debug folder looks as followed: 目前,在全新运行后,我的调试文件夹如下所示:

bin/
   └── x64
        └── Debug
            ├── AutoItX3.Assembly.dll
            ├── AutoItX3.Assembly.xml
            ├── Application.exe
            ├── Application.exe.config
            └── Application.pdb

i would like the AutoItX3_x64.dll included automatically on x64 builds, and if possible, the AutoIt3.dll included on x86 builds (its not currently set up for x86 builds, i just want to know how) 我想在x64版本中自动包含AutoItX3_x64.dll ,如果可能的AutoIt3.dll ,x86版本中包含AutoIt3.dll (它目前没有为x86版本设置,我只想知道如何)

Additional Information 附加信息

my launch.json 我的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "clr",
            "request": "launch",
            "preLaunchTask": "compile",
            "program": "${workspaceFolder}/Application/bin/x64/Debug/StartApplication.exe",
            "args": ["./Download/start.json"],
            "cwd": "${workspaceFolder}",
            "console": "externalTerminal",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "clr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

my tasks.json 我的tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile",
            "type": "shell",
            "command": "dotnet",
            "args": [
                // Ask msbuild to generate full paths for file names.
                "msbuild",
                "Application.sln",
                "/property:GenerateFullPaths=true",
                "/property:Platform=x64"
            ],
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "silent"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}

Application.sln


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Application\Application.csproj", "{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Debug|x86 = Debug|x86
        Debug|x64 = Debug|x64
        Release|Any CPU = Release|Any CPU
        Release|x86 = Release|x86
        Release|x64 = Release|x64
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x86.ActiveCfg = Debug|x86
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x86.Build.0 = Debug|x86
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x64.ActiveCfg = Debug|x64
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x64.Build.0 = Debug|x64
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|Any CPU.Build.0 = Release|Any CPU
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x86.ActiveCfg = Release|x86
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x86.Build.0 = Release|x86
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x64.ActiveCfg = Release|x64
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x64.Build.0 = Release|x64
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal

What I know and what I've tried 我所知道的和我尝试过的

microsofts docs show that you can use a metatag <DependentUpon> , which i tried with no luck. microsofts docs显示你可以使用metatag <DependentUpon> ,我试过没有运气。
The docs also mention conditions which are used else-ware in the .csproj , which make me think that once i have one configuration that works, i can make a condition to make it work for both platforms. 文档还提到了在.csproj中使用了else-ware的条件 ,这让我觉得一旦我有一个有效的配置,我就可以创建条件使其适用于两个平台。
One more thing that seems like it could solve this specific issue is tasks , but this feels very brute-force-ish, and i wouldn't know how to parse the .csproj for all external, local DLLs to move. 似乎可以解决这个特定问题的另一件事是任务 ,但这感觉非常强大,我不知道如何解析所有外部本地DLL移动的.csproj

this post was really helpful in explaining how to link content. 这篇文章真的有助于解释如何链接内容。

<ItemGroup>
  <Content Include="..\Shared\SharedSettings.json" Link="SharedSettings.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

By using the conditionals from the linked documentation in the question , I was able to move the DLLsfor x86 and x64 respectively. 通过使用问题中链接文档的条件,我能够分别移动x86和x64的DLL。

This was the final solution for the .csproj 这是.csproj的最终解决方案

<ItemGroup>
    <Reference Include="AutoItX">
      <HintPath>$(ProjectDir)\Lib\AutoItX\AutoItX3.Assembly.dll</HintPath>
    </Reference>
    <Content Include="$(ProjectDir)\Lib\AutoItX\AutoItX3_x64.dll" Condition="'$(Platform)' == 'x64'" Link="AutoItX3_x64.dll" CopyToOutputDirectory="PreserveNewest" />
    <Content Include="$(ProjectDir)\Lib\AutoItX\AutoItX3.dll" Condition="'$(Platform)' == 'x86'" Link="AutoItX3.dll" CopyToOutputDirectory="PreserveNewest" />
  </ItemGroup>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM