我的项目目标是从Microsoft CRM中获取数据并将其上传到PostGresSQL DB。当我手动运行可执行文件时,一切正常,但是当我在“任务计划程序”上作为计划任务运行应用程序时,出现以下错误:

“无法加载文件或程序集'Npgsql,版本= 4.0.5.0,区域性=中性,PublicKeyToken = 5d8b90d52f46fda7”或其依赖项之一。系统找不到指定的文件”。

我尝试将以下内容添加到我的.csproj文件中,但还是没有运气

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>  
 <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

一切正常,直到达到下面的功能。由于不会在控制台中写入“打印测试”,因此不会进入该功能。

    public void upToPostgresDB(string queryString)
            {
                Console.WriteLine("Print Test");
    #if DEBUG
    //Credentials below are not actually blank, I just removed them for privacy

                String pgDatabase = "";
                String pgServer = "";
                String pgUser = "";
                String pgPass = "";
    #else
                String pgDatabase = "";
                String pgServer = "";
                String pgUser = "";
                String pgPass = "";
    #endif

                String pgConnectionString = String.Format("Server={0}; UserId={1}; Password={2}; Database={3}", pgServer, pgUser, pgPass,     pgDatabase);
            NpgsqlConnection pgCon = new NpgsqlConnection(pgConnectionString);
            NpgsqlCommand cmd = new NpgsqlCommand(queryString, pgCon);            
            try
            {

                pgCon.Open();
                cmd.ExecuteNonQuery();
                pgCon.Close();
            }
            catch (Exception e)
            {
                string errorMessage = "Failed to upload data to the postgres database.  " + e.Message;
                Console.WriteLine(errorMessage);
                pgCon.Close();
            }
        }